Reputation: 1085
I use makefile to compile my C++ program, but it shows a warning:
make
g++ -g -std=c++0x -o ns-client main.cpp Client.cpp TCPConnect.cpp RSAsample.cpp libStatic/libchilkat_i386.a libStatic/libchilkat_x86_64.a -lpthread
ld: warning: ignoring file libStatic/libchilkat_i386.a, file was built for archive which is not the architecture being linked (x86_64): libStatic/libchilkat_i386.a
My makefile is as follows:
cat Makefile
LIBS = libStatic/libchilkat_i386.a libStatic/libchilkat_x86_64.a -lpthread
GPP = g++ -g -std=c++0x
TARGET = -o ns-client
CPP = main.cpp Client.cpp TCPConnect.cpp RSAsample.cpp
all:
$(GPP) $(TARGET) $(CPP) $(LIBS)
clean:
rm ns-client
libchilkat_i386.a
and libchilkat_x86_64.a
are downloaded by me, not implemented by me. I put them under a directory called "libStatic".
These are all my C++ files and lib:
ls
Client.cpp RSAsample.cpp libStatic
Client.h RSAsample.h main.cpp
Client_Common.h TCPConnect.cpp ns-client
Common_Num_Define.h TCPConnect.h ns-client.dSYM
Common_Protocol.h include ns-server
Makefile libDyn
In libStatic directory, it has:
ls
libchilkat_i386.a libchilkat_x86_64.a
I don't know why this warning happens. Even though it has this warning, it still compile successfully. But when I upload them to our school's server and compile them(I definitely upload these static libs), it shows:
undefined reference to
Many these kinds of errors. For example:
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:17: undefined reference to `CkRsa::exportPublicKey()'
All these functions and vars which are mentioned in these kinds of errors should be included in libchilkat_i386.a libchilkat_x86_64.a
So I doubt maybe it is because of my Makefile.But I am not sure. I also doubt that maybe related to the first warning. Can somebody tells me how solve the first warning or why it cannot compile on another machine but can compile on my own machine? Thanks for everyone's help!
This is all errors it showed on our school's server:
/tmp/ccA32Kao.o: In function `My_RSA::My_RSA()':
main.cpp:(.text._ZN6My_RSAC2Ev[_ZN6My_RSAC5Ev]+0x19): undefined reference to `CkRsa::CkRsa()'
main.cpp:(.text._ZN6My_RSAC2Ev[_ZN6My_RSAC5Ev]+0x2b): undefined reference to `CkRsa::CkRsa()'
main.cpp:(.text._ZN6My_RSAC2Ev[_ZN6My_RSAC5Ev]+0x3d): undefined reference to `CkRsa::CkRsa()'
main.cpp:(.text._ZN6My_RSAC2Ev[_ZN6My_RSAC5Ev]+0x54): undefined reference to `CkRsa::~CkRsa()'
main.cpp:(.text._ZN6My_RSAC2Ev[_ZN6My_RSAC5Ev]+0x69): undefined reference to `CkRsa::~CkRsa()'
/tmp/ccA32Kao.o: In function `My_RSA::~My_RSA()':
main.cpp:(.text._ZN6My_RSAD2Ev[_ZN6My_RSAD5Ev]+0x1a): undefined reference to `CkRsa::~CkRsa()'
main.cpp:(.text._ZN6My_RSAD2Ev[_ZN6My_RSAD5Ev]+0x2c): undefined reference to `CkRsa::~CkRsa()'
main.cpp:(.text._ZN6My_RSAD2Ev[_ZN6My_RSAD5Ev]+0x3c): undefined reference to `CkRsa::~CkRsa()'
/tmp/cciEnFVR.o: In function `Client::Register()':
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:17: undefined reference to `CkRsa::exportPublicKey()'
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:18: undefined reference to `CkRsa::exportPrivateKey()'
/tmp/cciEnFVR.o: In function Client::Login()':
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:128: undefined reference to
CkRsa::exportPublicKey()'
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:129: undefined reference to CkRsa::exportPrivateKey()'
/tmp/cciEnFVR.o: In function
Client::Judge_Command(char*)':
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:930 : undefined reference to CkRsa::exportPrivateKey()'
/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:931: undefined reference to
CkRsa::exportPublicKey()'
/tmp/ccRMXreb.o: In function My_RSA::MyEncryption(char const*, char const*)':
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 16: undefined reference to
CkRsa::put_EncodingMode(char const*)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 17: undefined reference to CkRsa::ImportPublicKey(char const*)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 25: undefined reference to
CkRsa::encryptStringENC(char const*, bool)'
/tmp/ccRMXreb.o: In function My_RSA::MyDecryption(char*)':
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 33: undefined reference to
CkRsa::put_EncodingMode(char const*)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 34: undefined reference to CkRsa::ImportPrivateKey(char const*)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 42: undefined reference to
CkRsa::decryptStringENC(char const*, bool)'
/tmp/ccRMXreb.o: In function My_RSA::My_Initial_Key()':
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 52: undefined reference to
CkRsa::UnlockComponent(char const*)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 58: undefined reference to CkRsa::GenerateKey(int)'
/home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 61: undefined reference to
CkMultiByteBase::lastErrorText()'
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
All these functions which should belong to CKRsa are in #include "include/CkRsa.h"
, but I definitely create the "include" directory on our school's server and upload these CKRsa.h files in that directory.
I revise my makefile,but it still doesn't work:
cat Makefile
LFLAGS += -L /home/users/liuly/liuly/networksecurity/project/cplus/client/libStatic
LIBS = libStatic/libchilkat_x86_64.a -lpthread
GPP = g++ -g -std=c++0x
TARGET = -o ns-client
CPP = main.cpp Client.cpp TCPConnect.cpp Common_Protocol.h RSAsample.cpp TCPConnect.h Client.h RSAsample.h include/CkRsa.h
all:
$(GPP) $(LFLAGS) $(TARGET) $(CPP) $(LIBS)
I revise makefile again, but it still doesn't work:
cat Makefile
LFLAGS += -L /home/users/liuly/liuly/networksecurity/project/cplus/client/libStatic
LIBS = -lchilkat_x86_64 -lpthread
GPP = g++ -g -std=c++0x
TARGET = -o ns-client
CPP = main.cpp Client.cpp TCPConnect.cpp Common_Protocol.h RSAsample.cpp TCPConnect.h Client.h RSAsample.h include/CkRsa.h
all:
$(GPP) $(LFLAGS) $(TARGET) $(CPP) $(LIBS)
Upvotes: 1
Views: 1317
Reputation: 1085
Now I see why this happens. My professor tells me that the static library which is downloaded from internet is only used for MAC OS (my own laptop is MAC), but our school's server is ubuntu. So i need to download the ubuntu version,otherwise our server cannot recognize the static lib. nm -a libchilkat_x86_64.a |less using this command to check whether it can be recognized. When I use this command on our server,it shows:
nm: C_CkString.o: File format not recognized etc
Upvotes: 0
Reputation: 129524
The library problem (built for a different architecture) is easily fixed by NOT using the library that you don't want. If you are publishing a makefile, you'll have to use some sort of configuration setting to determine the right architecture. If it's just your own project, pick the one that matches your system (by the looks of your makefile, the x86_variant).
The error CkRsa::exportPublicKey
is caused by your client code: The official symbol is CkRsa::ExportPublicKey
- note the uppercase E
at the beginning of the function name.
Here's the header file: http://smart-refrigerator-hbnu.googlecode.com/svn/branches/kmy/RFID_CLIENT_/include/CkRsa.h
Upvotes: 1