g++
-lpthread -o test test.o init.o ethernet.o
ethernet.o: In function `CEthernet::startConnection(int, int)':
ethernet.cpp:(.text+0x232): undefined reference to `pthread_create'
ethernet.o: In function `CEthernet::joinRecvThread()':
ethernet.cpp:(.text+0x722): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'all' failed
ethernet.o: In function `CEthernet::startConnection(int, int)':
ethernet.cpp:(.text+0x232): undefined reference to `pthread_create'
ethernet.o: In function `CEthernet::joinRecvThread()':
ethernet.cpp:(.text+0x722): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
Makefile:3: recipe for target 'all' failed
解决办法是:
g++ -pthread -o test test.o init.o ethernet.o
这个-lpthread与-pthread的区别参见如下的文章
http://blog.chinaunix.net/uid-25909722-id-3026989.html
摘录其中的一句话:
“所以: 一句话,我们现在应该使用 -pthread 而不是 -lpthread” 。