文件是为存档而构建的,而不是链接的体系结构(x86_64)

时间:2015-03-03 07:47:24

标签: c++ compilation makefile

我使用makefile编译我的C ++程序,但它显示一个警告:

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

我的makefile如下:

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.alibchilkat_x86_64.a由我下载,未由我实施。我把它们放在一个名为“libStatic”的目录下。 这些都是我的C ++文件和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

在libStatic目录中,它具有:

ls
libchilkat_i386.a   libchilkat_x86_64.a

我不知道为什么会发生这种警告。即使它有此警告,它仍然可以成功编译。但是当我将它们上传到我们学校的服务器并编译它们时(我肯定会上传这些静态库),它显示:

 undefined reference to   

很多这类错误。例如:

/home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:17: undefined reference to `CkRsa::exportPublicKey()'

libchilkat_i386.a libchilkat_x86_64.a中应包含这些错误中提到的所有这些功能和变量。 所以我怀疑是因为我的Makefile。但我不确定。我也怀疑可能与第一次警告有关。有人能告诉我如何解决第一个警告或为什么它不能在另一台机器上编译但可以在我自己的机器上编译?谢谢大家的帮助!

这是我们学校服务器上显示的所有错误:

/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:在函数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:对CkRsa::exportPrivateKey()' /tmp/cciEnFVR.o: In function Client :: Judge_Command(char *)'的未定义引用:     /home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:930:未定义引用CkRsa::exportPrivateKey()' /home/users/liuly/liuly/networksecurity/project/cplus/client/Client.cpp:931: undefined reference to CkRsa :: exportPublicKey()'     /tmp/ccRMXreb.o:在函数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:未定义引用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:在函数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:对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:在函数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:未定义引用CkRsa::GenerateKey(int)' /home/users/liuly/liuly/networksecurity/project/cplus/client/RSAsample.cpp: 61: undefined reference to CkMultiByteBase :: lastErrorText()'     collect2:错误:ld返回1退出状态     make:*** [all]错误1

所有这些属于CKRsa的函数都在#include "include/CkRsa.h"中,但我肯定会在学校的服务器上创建“include”目录,并将这些CKRsa.h文件上传到该目录中。

我修改了我的makefile,但它仍然不起作用:

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)

我再次修改了makefile,但它仍然不起作用:

 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)

2 个答案:

答案 0 :(得分:1)

通过NOT使用您不想要的库,可以轻松解决库问题(针对不同架构而构建)。如果要发布makefile,则必须使用某种配置设置来确定正确的体系结构。如果它只是您自己的项目,请选择与您的系统匹配的项目(通过makefile的外观,x86_variant)。

错误CkRsa::exportPublicKey是由您的客户端代码引起的:官方符号为CkRsa::ExportPublicKey - 请注意函数名称开头的大写E

这是头文件: http://smart-refrigerator-hbnu.googlecode.com/svn/branches/kmy/RFID_CLIENT_/include/CkRsa.h

答案 1 :(得分:0)

现在我明白为什么会这样。我的教授告诉我,从互联网上下载的静态库仅用于MAC OS(我自己的笔记本电脑是MAC),但我们学校的服务器是ubuntu。所以我需要下载ubuntu版本,否则我们的服务器无法识别静态库。 nm -a libchilkat_x86_64.a | less使用此命令检查是否可以识别它。 当我在服务器上使用此命令时,它显示:

nm:C_CkString.o:无法识别文件格式等