0

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
20
  • 1
    You have to put -lpthread at the end of the linker invocation. Commented Apr 13, 2014 at 19:12
  • I just run the 'make' command, how do I specify that it puts it at the end? Also, I copypasted the 'g++ ...' command and ran it manually and now its giving me a 'mutliple definition error' Commented Apr 13, 2014 at 19:25
  • @userXXX modify your Makefile using a... wait for it... text editor! Commented Apr 13, 2014 at 19:29
  • I guess it is the same thing if I copy-paste the command line the gives the error and manually put -lpthread at the end, which is what I did and it still does not work, because now it gives me the multiple references error message. Commented Apr 13, 2014 at 19:42
  • Did the ./configure command output any error? Also, what platform are you compiling on? Commented Apr 13, 2014 at 19:46

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

If i'm doing it on windows with mingw, do you know how it works there?
I already used pthread instead of lpthread both in the beginning and in the end of the command and it is not working both cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.