为什么我得到pthread_mutexattr_settype的未定义引用?

 小群群zheng 发布于 2023-01-20 08:30

我正在尝试编译和链接Novell LDAP C SDK中的示例文件,但由于pthread库中有3个未解析的符号,链接失败.我在Ubuntu 13.10(Saucy)上使用gcc 4.8.1.我已将pthread库正确地包含在命令行中的最后一个库中,但这些特定符号仍未解析.

$ gcc -Wl,-trace-symbol=pthread_mutexattr_settype -Wl,-trace-symbol=pthread_mutexattr_init   -Wl,-trace-symbol=pthread_mutex_trylock  -o search search.o -L../lib -lldapsdk -lpthread

../lib/libldapsdk.so: reference to pthread_mutexattr_settype
../lib/libldapsdk.so: reference to pthread_mutexattr_init
../lib/libldapsdk.so: reference to pthread_mutex_trylock
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_settype
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_init
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutex_trylock
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_settype
../lib/libldapsdk.so: undefined reference to pthread_mutex_trylock
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_init
collect2: error: ld returned 1 exit status $ readelf --all /lib/i386-linux-gnu/libpthread.so.0|grep pthread_mutexattr_settype
114: 00009d90 36 FUNC GLOBAL DEFAULT 13 pthread_mutexattr_settype@@GLIBC_2.1
493: 00009d90 36 FUNC GLOBAL DEFAULT 13 pthread_mutexattr_settype

Ali.. 23

只需将评论作为答案撰写,因为根据其他用户的反馈证明它是有用的.


请传递-pthread给编译器(不带-l).另请参阅gcc - 编译时-pthread标志的重要性.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有