Makefile'未定义引用'错误

时间:2014-04-13 19:05:31

标签: c++ reference makefile undefined

我正在研究一个IRC-Bot,我正在运行已经完成的机器人'make',我想要修改。 但是,我收到以下'未定义引用'错误:

g++  -g -O2 -lpthread  -o markovsky-irc markovsky.o markovutil.o markovsky-irc.o botnet.o dcc_chat.o dcc_send.o output.o server.o utils.o  
botnet.o: In function `BN_getthreadspecific':
/home/bavor/Applications/markovsky-0.53/botnet/botnet.c:113: undefined reference to `pthread_once'
/home/bavor/Applications/markovsky-0.53/botnet/botnet.c:114: undefined reference to `pthread_getspecific'
/home/bavor/Applications/markovsky-0.53/botnet/botnet.c:119: undefined reference to `pthread_setspecific'
botnet.o: In function `BN_Connect':
/home/bavor/Applications/markovsky-0.53/botnet/botnet.c:154: undefined reference to `pthread_create'
botnet.o: In function `BN_tsinitkey':
/home/bavor/Applications/markovsky-0.53/botnet/botnet.c:95: undefined reference to `pthread_key_create'
dcc_chat.o: In function `BN_AcceptDCCChat':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_chat.c:216: undefined reference to `pthread_create'
dcc_chat.o: In function `BN_SendDCCChatRequest':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_chat.c:97: undefined reference to `pthread_create'
dcc_chat.o: In function `BN_AcceptDCCChat':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_chat.c:217: undefined reference to `pthread_detach'
dcc_chat.o: In function `BN_SendDCCChatRequest':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_chat.c:98: undefined reference to `pthread_detach'
dcc_send.o: In function `BN_SendDCCSendRequest':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_send.c:102: undefined reference to `pthread_create'
dcc_send.o: In function `BN_AcceptDCCSend':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_send.c:245: undefined reference to `pthread_create'
dcc_send.o: In function `BN_SendDCCSendRequest':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_send.c:103: undefined reference to `pthread_detach'
dcc_send.o: In function `BN_AcceptDCCSend':
/home/bavor/Applications/markovsky-0.53/botnet/dcc_send.c:246: undefined reference to `pthread_detach'
utils.o: In function `BN_UnsetSigs':
/home/bavor/Applications/markovsky-0.53/botnet/utils.c:257: undefined reference to `pthread_sigmask'
collect2: error: ld returned 1 exit status
make: *** [markovsky-irc] Error 1

我不知道是否需要在这里显示Makefile,因为它很长。 我已经搜索过这个错误,但我无法找到任何可以帮助我解决此错误的内容,我希望能在这里找到一些个人帮助。谢谢!

编辑:./ configure输出:

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands

1 个答案:

答案 0 :(得分:0)

您的平台文档应指定如何正确获取POSIX pthreads支持。对于大多数Linux发行版,您将-pthread标志传递给编译器和链接器。通常,编译器标志除了链接器标志链接到pthreads库之外什么都不做。

请勿使用-lpthread。它不可移植,将来不仅仅需要链接到库。例如,在某些平台上可能需要将-DTHREAD_SAFE传递给编译器。