Author Topic: undefined reference to `pthread_create'  (Read 19555 times)

Tikara

  • Guest
undefined reference to `pthread_create'
« on: July 21, 2006, 09:26:43 pm »
Hi,

I'm running Code::Blocks on Ubuntu.  I've been having some problems getting threads to work with C++, so I thought I'd try the example code I have for C.  The code compiles and runs fine if I use the command line.  However, when I try to compile the same file in Code::Blocks, the linker complains about an undefined reference to pthread_create.  I've tried adding in various defines, but I've not got anywhere with it - can someone tell me where I'm going wrong?

The output is:

Project   : Console application
Compiler  : GNU GCC Compiler (called directly)
Directory : /home/tika/Projects/Test/
--------------------------------------------------------------------------------
Switching to target: default
Linking console executable: /home/tika/Projects/Test/test
.objs/main.o: In function `main':
main.c:(.text+0x2d): undefined reference to `pthread_create'
main.c:(.text+0x73): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings

It makes sense to ask about the problem I was having with the C++ version too.  The code compiled, but the pthread_create function didn't start the thread.  Again, can someone tell me where I'm going wrong?

Thanks,

Rachel.
 


Offline Ceniza

  • Developer
  • Lives here!
  • *****
  • Posts: 1441
    • CenizaSOFT
Re: undefined reference to `pthread_create'
« Reply #1 on: July 21, 2006, 09:40:13 pm »
Are you sure you added pthread to the list of libraries to link against in the project file? It'd be useful if you compared the command line you're using to compile it and the one generated by Code::Blocks.

To check the line Code::Blocks is issuing go to Settings -> Compiler and debugger -> Other. Compiler logging: "Full command line".