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
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.