'Cmake linker script cannot find proper libraries
I am having a libpthread linker issue in Cmake while cross-compiling using Cmake. My cmake toolchain file looks like:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_SYSTEM_VERSION 1)
# Specify Sysroot path
SET(CMAKE_SYSROOT /root/br-tcg4/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/)
# Specify path to find filesystem items
SET(CMAKE_FIND_ROOT_PATH /root/br-tcg4/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/)
# Search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Search for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
# Specify toolchain directory
#SET(TOOLCHAIN_DIR /home/toolchain/dir/here/bin)
SET(TOOLCHAIN_DIR /root/br-tcg4/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin)
# Specify cross compilation target
SET(TARGET_CROSS arm-linux-gnueabihf-)
# Set compilers
SET(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/${TARGET_CROSS}g++)
# Set linker
SET(CMAKE_LINKER ${TOOLCHAIN_DIR}/${TARGET_CROSS}ld)
# Set compiler flags
SET(CMAKE_CXX_FLAGS ${COMMON_FLAGS} -std=c++11)
# Set archiving tool
SET(CMAKE_AR ${TOOLCHAIN_DIR}/${TARGET_CROSS}ar CACHE FILEPATH "Archiver")
# Set randomizing tool for static libraries
SET(CMAKE_RANLIB ${TOOLCHAIN_DIR}/${TARGET_CROSS}ranlib)
# Set strip tool
SET(CMAKE_STRIP ${TOOLCHAIN_DIR}/${TARGET_CROSS}strip)
# Set objdump tool
SET(CMAKE_OBJDUMP ${TOOLCHAIN_DIR}/${TARGET_CROSS}objdump)
# Set objcopy tool
SET(CMAKE_OBJCOPY ${TOOLCHAIN_DIR}/${TARGET_CROSS}objcopy)
# Set nm tool
SET(CMAKE_NM ${TOOLCHAIN_DIR}/${TARGET_CROSS}nm)
# Set THREADS_PTHREAD_ARG for testing threading
SET(THREADS_PTHREAD_ARG "2" CACHE STRING "Forcibly set by ToolchainFile.cmake." FORCE)
And doing out-of-source build compilation using cmake ../. -DCMAKE_TOOLCHAIN_FILE=[...]/ToolchainFile.cmake. Compilation is successful and generated build files.
But when I do make I get below errors:
/root/br-tcg4/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/libpthread.so.0
/root/br-tcg4/opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.5.0/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/libpthread_nonshared.a
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/awsclient.dir/build.make:204: src/awsclient] Error 1
make[1]: *** [CMakeFiles/Makefile2:554: src/CMakeFiles/awsclient.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
The dir opt/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib contains both libpthread.so and libpthread_nonshared.a.
After going through some other posts, I edited the libpthread linker script to below:
/* 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 )
And also libc.so 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 ( libc.so.6 libc_nonshared.a AS_NEEDED ( ld-linux-armhf.so.3 ) )
But still I have the same issues. I don't understand why it can't find the proper libraries and header files.
Can anyone please let em know how to fix this and make it work?
Your help will be much appreciated.
Thanks in advance.
P.S: I am using Buildroot and Ubuntu 20.04 as build system. please let me know if any info is missing here.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
