当前位置: 技术问答>linux和unix
该怎么编译?
来源: 互联网 发布时间:2015-07-18
本文导语: 我想静态编译一段程序,命令如下:g++ -lpthread msgtest.c -o msgtest -static,就是想静态编译msgtest.c代码,里边包含有线程相关函数,我用上面编译后,出现如下提示: /tmp/cctpzVLi.o(.text+0x4c6): In function `main': : undefined...
我想静态编译一段程序,命令如下:g++ -lpthread msgtest.c -o msgtest -static,就是想静态编译msgtest.c代码,里边包含有线程相关函数,我用上面编译后,出现如下提示:
/tmp/cctpzVLi.o(.text+0x4c6): In function `main':
: undefined reference to `pthread_join'
/tmp/cctpzVLi.o(.text+0x4d6): In function `main':
: undefined reference to `pthread_join'
/tmp/cctpzVLi.o(.text+0x4e4): In function `main':
: undefined reference to `pthread_cancel'
/tmp/cctpzVLi.o(.text+0x4f2): In function `main':
: undefined reference to `pthread_cancel'
collect2: ld returned 1 exit status
make: *** [msgtest] Error 1
请问我该怎么解决?
/tmp/cctpzVLi.o(.text+0x4c6): In function `main':
: undefined reference to `pthread_join'
/tmp/cctpzVLi.o(.text+0x4d6): In function `main':
: undefined reference to `pthread_join'
/tmp/cctpzVLi.o(.text+0x4e4): In function `main':
: undefined reference to `pthread_cancel'
/tmp/cctpzVLi.o(.text+0x4f2): In function `main':
: undefined reference to `pthread_cancel'
collect2: ld returned 1 exit status
make: *** [msgtest] Error 1
请问我该怎么解决?
|
要把-lpthread放到msgtest.c的后面位置,因为连接器找符号的时候,是按照从前到后顺序找的,前面没有定义的符号不会到再前面去搜索。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。