我正在使用/usr/include/nptl/pthread.h中的pthread_setaffinity_np等函数。
然而,链接器抱怨没有找到“pthread_setaffinity_np”,据我所知,链接器正在错误的pthread库(/usr/lib/libpthread.so)中查找引用,该库不支持CPU关联。我在红帽4号。
我认为我必须链接到/lib/tls/libpthread-2.3.4.so,其中包括这个函数。但是,链接到libpthread-2.3.4.so会导致其他链接器错误。
链接到libpthread-2.3.4的正确方式是什么,那么RedHat 4呢?
提前谢谢你,
保罗

最佳答案

据我所知,链接器正在错误的pthread库中查找引用
你的理解不正确。
/usr/lib/libpthread.so是一个链接器脚本,它将您的程序与libpthread.so.0libpthread_nonshared.a链接起来。libpthread.so.0是(应该是)符号链接,最有可能是libpthread-2.3.4.so
您的系统上可能安装了几个版本的libpthread-2.3.4.so:一个在/lib/i686,一个在/lib/tls,也许还有一个在/lib。运行时使用哪一个取决于硬件和内核。
以下命令打印什么?

find /lib -name 'libpthread.so.0' | xargs nm -A | grep pthread_setaffinity_np

ldd /usr/bin/date

10-07 15:03