The command line used to compile a single file program of pthread is:
Gcc-O thread1-lpthread thread1.c
Error:
1 $ gcc -o thread1 -lpthread thread1.c2 /tmp/ccNqs6Bh.o: In function `main‘:3 thread1.c:(.text+0x49): undefined reference to `pthread_create‘4 thread1.c:(.text+0x5f): undefined reference to `pthread_join‘5 collect2: error: ld returned 1 exit status
After a careful look, the Code has been compiled and the link has an error, but the pthread library actually exists.
In addition, the GCC syntax is:
Usage: GCC [Options] file...
It's my favorite parameter passing method, and it's also passed in the prescribed way. Why? Do not play like this!
Take a closer look and find a '-V -- help' option, so gcc-V -- Help, [email protected] # $ % ^ &
The output result contains nearly 3000 rows !!!, Scare urine ~~~~~~~
No way. Google has the following instructions:
1. Link order of Libraries
2. c ++ shared library-undefined reference
Solution:
Put the reference to the library behind the source file, because it is a parameter passed to the linker!
To change it to this:
Gcc-O thread1 thread1.c-lpthread
Girl don't cry @ cnblogs.com/memset @ 2014.11.04
A summary of the undefined reference caused by incorrect GCC parameter-l transfer sequence