user2308896
user2308896

Reputation: 3

Makefile 'undefined reference' error

I am working on an IRC-Bot and I am at the point of running 'make' on a bot that is already finished and I want to possibly modify. However, I get the following 'undefined reference' error:

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

I don't know if I need to show the Makefile here, since it is pretty long. I have searched for this error already but I couldnt really find anything that could help me resolve this error and I was hoping to find some individual help here. Thanks!

edit: ./configure output:

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

Upvotes: 0

Views: 2203

Answers (1)

David Schwartz
David Schwartz

Reputation: 182733

Your platform's documentation should specify how to correctly get POSIX pthreads support. For most Linux distributions, you pass the -pthread flag to both the compiler and the linker. Typically, the compiler flag does nothing but the linker flag links to the pthreads library.

Do not use -lpthread. It's not portable, and in the future more than just linking to the library might be needed. For example, passing -DTHREAD_SAFE to the compiler might be required on some platforms.

Upvotes: 1

Related Questions