gpt4 book ai didi

c - 为什么我得到对 pthread_mutexattr_settype 的 undefined reference ?

转载 作者:IT王子 更新时间:2023-10-28 23:52:10 38 4
gpt4 key购买 nike

我正在尝试从 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<br>
../lib/libldapsdk.so: reference to pthread_mutexattr_init<br>
../lib/libldapsdk.so: reference to pthread_mutex_trylock<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_settype<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutexattr_init<br>
/lib/i386-linux-gnu/libpthread.so.0: definition of pthread_mutex_trylock<br>
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_settype<br>
../lib/libldapsdk.so: undefined reference to pthread_mutex_trylock<br>
../lib/libldapsdk.so: undefined reference to pthread_mutexattr_init<br>
collect2: error: ld returned 1 exit status

$ readelf --all /lib/i386-linux-gnu/libpthread.so.0|grep pthread_mutexattr_settype<br>
114: 00009d90 36 FUNC GLOBAL DEFAULT 13 pthread_mutexattr_settype@@GLIBC_2.1<br>
493: 00009d90 36 FUNC GLOBAL DEFAULT 13 pthread_mutexattr_settype

最佳答案

只是写下评论作为答案,因为根据其他用户的反馈证明它有帮助。


请将-pthread 传递给编译器(不带-l)。另见 gcc - significance of -pthread flag when compiling .

关于c - 为什么我得到对 pthread_mutexattr_settype 的 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22180354/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com