I am having some troubles setting up cross compiling with CMAKE. The toolchain I am using is created in yocto which works perfectly outside of cmake.
I have followed a tutorial to setup the following toolchain file:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)
SET(CMAKE_SYSTEM_PROCESSOR arm)
# specify the cross compiler
SET(tools /opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr)
SET(CMAKE_C_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER ${tools}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
# set sysroot
SET(CMAKE_SYSROOT /home/sifu/test-yocto/qemuarmdfs)
#SET(CMAKE_FIND_ROOT_PATH /home/sifu/test-yocto/qemuarm)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# 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)
And get the following error when running cmake
The C compiler
"/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp
Run Build Command:/usr/bin/make "cmTryCompileExec4012536451/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec4012536451.dir/build.make
CMakeFiles/cmTryCompileExec4012536451.dir/build
make[1]: Entering directory
`/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report
/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp/CMakeFiles
1
Building C object
CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o
/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
-O2 -pipe -g -feliminate-unused-debug-types -o
CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o -c
/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTryCompileExec4012536451
/usr/bin/cmake -E cmake_link_script
CMakeFiles/cmTryCompileExec4012536451.dir/link.txt --verbose=1
/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
-O2 -pipe -g -feliminate-unused-debug-types -Wl,-O1 -Wl,--hash-style=gnu
-Wl,--as-needed CMakeFiles/cmTryCompileExec4012536451.dir/testCCompiler.c.o
-o cmTryCompileExec4012536451 -rdynamic
... (A lot of ld errors similar to the one below)
/opt/poky/1.7.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/4.9.1/ld:
cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
make[1]: Leaving directory
`/home/sifu/Projects/mv/doublepump-single-pump-sw.ss016m21_swapp/cc/CMakeFiles/CMakeTmp'
If I manually run the gcc command described in the log above with --sysroot=/home/sifu/test-yocto/qemuarmdfs it works for me. Why isn't cmake using the sysroot flag when the path to sysroot is added in the toolchain file.
--sysroot
option. Is lineThe C compiler identification is GNU
output by CMake when configure? BTW, you show toolchain with errorneous space before "gnueabi-gcc" inCMAKE_C_COMPILER
variable definition. This space is absent in your original toolchain file, isn't it?The C compiler identification is GNU 4.9.1.
. The space in CMAKE_C_COMPILER was just a cut and paste issue, i have edited the original question.CMAKE_C_FLAGS
somehow, so--sysroot
option disappears. Could you try to build simple "Hello world" program with your toolchain?--sysroot=/home/sifu/test-yocto/qemuarmdfs
.add_executable
). For such project CMake should add--sysroot
option automatically, and you can see it when build withmake V=1
.