1

tl;dr - CMake fails at linker not finding System library with precompiled RaspberryPi toolchain when other libraries work

So I've been fighting this for a few days, and I believe I'm nearing the end of my journey to get an ARM executable for the RaspberryPi compiled through CMake on macOS Sierra.

Currently, I'm using the pre-compiled RaspberryPi toolchain from this blog, and getting the following results:

macbook:gpsexample alex$ cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /Volumes/linuxdev/gpsexample
macbook:gpsexample alex$ make
[ 20%] Linking C executable gpsexample
clang: warning: argument unused during compilation: '-pthread' [-Wunused-command-line-argument]
ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gpsexample] Error 1
make[1]: *** [CMakeFiles/gpsexample.dir/all] Error 2
make: *** [all] Error 2

I've previously had problems linking the m library with the same error, however adding the proper system root fixed that issue. I have a feeling I'm missing another library or directory - however I'm not too sure where.

Below is my CMakeLists.txt (single file only):

cmake_minimum_required(VERSION 3.6.2)
project (gpsexample)

set(CMAKE_SYSROOT "/Volumes/xtools/armv8-rpi3-linux-gnueabihf/armv8-rpi3-linux-gnueabihf/sysroot")

#Enable POSIX Threading
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pthread")

#Bring the headers in
include_directories(include)

#Wildcard add all source files in dir
file(GLOB SOURCES "src/*.c")

#Create the target
add_executable(gpsexample ${SOURCES})

#Link the standard math lib to the exec
target_link_libraries(gpsexample m)

Is there somewhere else I should add for a library to get System found? Will I need to download the raw files from the Pi directly and include them in the custom tools directory?

Thanks for all the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.