Crosstools-ng找不到 pthread.so



我试图使用crostools -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 )

/* 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 )

查看此信息页: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

使用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_SYSROOT ${RPI_ROOT_PATH}),其中RPI_ROOT_PATH包含RPi sysroot的路径,而不是直接设置编译器标志。

相关内容

最新更新