crosstools-ng找不到pthread.so

时间:2013-01-08 02:05:56

标签: 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.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

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

3 个答案:

答案 0 :(得分:6)

编辑你的... / 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 )

/* 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 ( libpthread.so.0 libpthread_nonshared.a )

答案 1 :(得分:2)

查看此信息页面: https://sourceware.org/binutils/docs-2.24/ld/File-Commands.html#File-Commands

阅读INPUT和GROUP的定义,具体为:

如果配置了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

答案 2 :(得分:1)

使用GCC --sysroot=dir标志可以解决问题。 该标志告诉GCC搜索dir文件夹下的标题和库。

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

这对于修复与fullpath到库的链接特别有用。

使用CMake生成构建系统时,应使用SET(CMAKE_SYSROOT ${RPI_ROOT_PATH}),其中RPI_ROOT_PATH包含RPi sysroot的路径,而不是直接设置编译器标志。