crosstools-ng can't find pthread.so

前端 未结 3 1128
隐瞒了意图╮
隐瞒了意图╮ 2021-02-09 08:51

I am trying to use crosstools-ng to compile a program that uses pthread, however for some reason the linker can\'t find the library. I have checked and the libraries are located

相关标签:
3条回答
  • 2021-02-09 09:03

    See this info page: https://sourceware.org/binutils/docs-2.24/ld/File-Commands.html#File-Commands

    Read the definitions of INPUT and GROUP, specifically:

    In case a sysroot prefix is configured, and the filename starts with the `/' character, and the script being processed was located inside the sysroot prefix, the filename will be looked for in the sysroot prefix. Otherwise, the linker will try to open the file in the current directory. If it is not found, the linker will search through the archive library search path. See the description of `-L' in Command Line Options.

    So your linker script should be:

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

    ...as your toolchain is using a sysroot prefix.

    You can find your sysroot prefix with:

    <tuple>-gcc -print-sysroot
    
    0 讨论(0)
  • 2021-02-09 09:25

    Using the GCC --sysroot=dir flag should fix the issue. This flag tells GCC to search both headers and libraries under the dir folder.

    In your case, if you add --sysroot=/home/user/rpi_root to linker flags, ld will search for /home/user/rpi_root/lib/libpthread.so.0 instead of just /lib/libpthread.so.0.

    This is particularly helpful to fix linking with fullpath to library.

    When using CMake to generate build system, you should use SET(CMAKE_SYSROOT ${RPI_ROOT_PATH}), where RPI_ROOT_PATH contains the path to the RPi sysroot instead of directly set compiler flags.

    0 讨论(0)
  • 2021-02-09 09:28

    Edit your .../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 )
    

    to

    /* 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 )
    
    0 讨论(0)
提交回复
热议问题