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 in the link path specificed by -L
is the arguments.
Here is the error:
/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
Why can't ld find the file that is within the path?
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 )
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With