Gcc crosstools ng can';找不到pthread.so

Gcc crosstools ng can';找不到pthread.so,gcc,cross-compiling,Gcc,Cross Compiling,我试图使用crosstools ng编译一个使用pthread的程序,但是由于某些原因链接器找不到库。我已经检查过,库位于-L为参数指定的链接路径中 以下是错误: /home/***/raspberrypi/toolchain/lib/gcc/arm-unknown-linux-gnueabi/4.6.3/../../../.. /arm-unknown-linux-gnueabi/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.s

我试图使用crosstools ng编译一个使用pthread的程序,但是由于某些原因链接器找不到库。我已经检查过,库位于
-L
为参数指定的链接路径中

以下是错误:

/home/***/raspberrypi/toolchain/lib/gcc/arm-unknown-linux-gnueabi/4.6.3/../../../.. /arm-unknown-linux-gnueabi/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.so.0

/home/***/raspberrypi/toolchain/lib/gcc/arm-unknown-linux-gnueabi/4.6.3/../../../../arm-unknown-linux-gnueabi/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a

为什么找不到路径中的文件?

编辑您的…/usr/lib/arm-linux-gnueabihf/libpthread.so:

/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/arm-linux-gnueabihf/libpthread.so.0 /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a )

请参见此信息页面:

阅读输入和组的定义,具体如下:

如果配置了sysroot前缀,并且文件名以“/”字符开头,并且正在处理的脚本位于sysroot前缀内,则将在sysroot前缀中查找文件名。否则,链接器将尝试打开当前目录中的文件。如果未找到,链接器将通过存档库搜索路径进行搜索。请参见命令行选项中对“-L”的描述

因此,您的链接器脚本应该是:

/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily.  */
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( /lib/libpthread.so.0 /usr/lib/libpthread_nonshared.a )
…因为您的工具链正在使用sysroot前缀

您可以通过以下方式找到sysroot前缀:

<tuple>-gcc -print-sysroot
-gcc-print sysroot
使用GCC
--sysroot=dir
标志应该可以解决这个问题。 此标志告诉GCC搜索
dir
文件夹下的标题和库

在您的情况下,如果将
--sysroot=/home/user/rpi_root
添加到链接器标志中,
ld
将搜索
/home/user/rpi_root/lib/libpthread.so.0
而不仅仅是
/lib/libpthread.so.0

这对于修复与库的完整路径的链接特别有用


使用CMake生成生成系统时,应使用
SET(CMake\u SYSROOT${RPI\u ROOT\u PATH})
,其中
RPI\u ROOT\u PATH
包含指向RPI系统根的路径,而不是直接设置编译器标志。

该文件是一个断开的符号链接吗?如果我从/lib/arm linux gnueabihf和/usr/lib/arm linux gnueabihf添加一个符号链接,它将编译。目录中的符号链接都是相对的。/usr/lib/libpthread.so从您的工具链是一个链接器脚本。既然我不明白为什么这是/lib/arm-linux-gnueabihf/libpthread.so.0而不是常规的/lib/libpthread.so.0,你能发布这个文件的内容吗?我不知道你的工具链中的“/usr/lib/libpthread.so”是什么意思。在工具链根目录下的路径中有一个文件。是的,在工具链系统根目录中应该有一个具有此路径的文件。
<tuple>-gcc -print-sysroot