2

I try to cross compile a library (Wt) using CMake (2.8.12.2). I get always errors which tell me that it is not able to compile a simple test program. I do not know how to make cmake to look into the right path for getting object files. My development and target plattform is Linux.

The error log looks like this

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc 
Build flags: ;-O2;-pipe;-g;-feliminate-unused-debug-types;
Id flags: 

The output was:
1
/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/libexec/arm-reed-linux-gnueabi/gcc/arm-reed-linux-gnueabi/5.3.0/real-ld: cannot find crt1.o: No such file or directory
/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/libexec/arm-reed-linux-gnueabi/gcc/arm-reed-linux-gnueabi/5.3.0/real-ld: cannot find crti.o: No such file or directory
...

Here is my tool chain file. I could skip the test (See CMAKE_C_COMPILER_WORKS) but then I get later similar problems:

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

# Compiler and linker
SET(CMAKE_C_COMPILER "/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc")
SET(CMAKE_CXX_COMPILER "/opt/rhl/0.01/sysroots/x86_64-rhlsdk-linux/usr/bin/arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-g++")
SET(COMPILE_FLAGS " -march=armv7-a -marm -mfpu=neon  -mfloat-abi=hard -mcpu=cortex-a8 --sysroot=/opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi")
SET(CMAKE_EXE_LINKER_FLAGS " -O2 -v -o  --sysroot=/opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi ")

# Paths
SET(CMAKE_PREFIX_PATH /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/usr/)
SET(CMAKE_SYSROOT /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/)
SET(CMAKE_FIND_ROOT_PATH /opt/rhl/0.01/sysroots/cortexa8hf-neon-reed-linux-gnueabi/)

SET(CMAKE_COLOR_MAKEFILE ON)
set(SHARED_LIBS OFF)

# 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)

# skip the compiler tests 
# set(CMAKE_C_COMPILER_WORKS 1 CACHE INTERNAL "")
# set(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")

And here is a tree view of my system. I pruned it to show the relevant part.

/opt/rhl/0.01/sysroots
├── cortexa8hf-neon-reed-linux-gnueabi
│   ├── bin
│   ├── lib
│   ├── usr
│   │   ├── bin
│   │   ├── include
│   │   ├── lib
│   │   │   ├── crt1.o -> cmake cannot find this file
│   │   │   ├── crti.o -> cmake cannot find this file
│   │   ├── share
│   │   └── src
│   │           ├── gcc-runtime
│   │           │   └── 5.3.0-r0
└── x86_64-rhlsdk-linux
    ├── lib
    ├── sbin
    ├── usr
    │   ├── bin
    │   │   │   ├── arm-reed-linux-gcc -> ../arm-reed-linux-gnueabi/arm-reed-linux-gnueabi-gcc
    │   │   ├── arm-reed-linux-gnueabi
    │   │   │   ├── arm-reed-linux-gnueabi-gcc  -> The C compiler
    │   ├── include
    │   ├── lib
    │   ├── libexec
Truk
  • 21
  • 4
  • As you can see from error log, your compiler flags are not used. See [that question](https://stackoverflow.com/a/11536633/3440745) about proper setting compiler flags in toolchain. Also, setting [CMAKE_SYSROOT](https://cmake.org/cmake/help/v3.7/variable/CMAKE_SYSROOT.html) variable **automatically** provides `--sysroot` option for compiler, and given path is treated as one of *CMAKE_FIND_ROOT_PATH*. No needs to duplicate effects of sysroot. – Tsyvarev Jun 27 '17 at 08:47
  • Thank you, that was the solution. – Truk Jun 27 '17 at 12:38
  • Possible duplicate of [CMake cross-compiling: C flags from toolchain file ignored](https://stackoverflow.com/questions/11423313/cmake-cross-compiling-c-flags-from-toolchain-file-ignored) – Tsyvarev Jun 27 '17 at 12:40

0 Answers0