LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   undefined reference to 'pthread_create' from linker (https://www.linuxquestions.org/questions/programming-9/undefined-reference-to-pthread_create-from-linker-818399/)

CrazyDave 07-06-2010 10:55 PM

undefined reference to 'pthread_create' from linker
 
I am having trouble linking the pthread library.

I have -lpthread -lm as options for the GNU GCC compiler.

Build Log
------------------------------------------------------------
Compiling: main.c
Compiling: matrix.c
Compiling: newmalloc.c
Linking console executable: bin/Release/optimizer-4
obj/Release/main.o: In function `main':
main.c:(.text+0x132): undefined reference to `pthread_attr_setstacksize'
main.c:(.text+0x224): undefined reference to `pthread_create'
main.c:(.text+0x35b): undefined reference to `pthread_join'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors
-------------------------------------------------------------
library search:
dlyon@dlyon-desktop2:~$ ls /usr/lib |grep pthread
libgpgme-pthread.so.11
libgpgme-pthread.so.11.7.0
libpthread.a
libpthread_nonshared.a
libpthread.so
dlyon@dlyon-desktop2:~$
-------------------------------------------------------------

Any ideas would be greatly appreciated! Thanks!

John VV 07-06-2010 11:30 PM

with out knowing what you are building we can not even guess
something is missing in some code ?? as to what ??
without seeing it ....

Wim Sturkenboom 07-06-2010 11:55 PM

From man gcc (search for -llibrary in there)
Quote:

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.
Maybe that's the problem?


All times are GMT -5. The time now is 06:30 AM.