关于cmake is not able to compile a simple test program

指定了交叉编译

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_FIND_ROOT_PATH "/opt/mips/eldk4.1/usr/bin")
set(CMAKE_C_COMPILER "${CMAKE_FIND_ROOT_PATH}/mips_4KC-gcc")

但报错compile tools can not be able to build a simple program

如下可解决

You don't have to write a toolchain file for every piece of software you want to build, the toolchain files are per target platform, i.e. if you are building several software packages all for the same target platform, you have to write only one toolchain file and you can use this for all packages.

If your compiler is not able to build a simple program by default without special flags or files (e.g. linker scripts or memory layout files), the toolchain file as shown above doesn't work. Then you have to force the compiler:

INCLUDE(CMakeForceCompiler)

# this one is important
SET(CMAKE_SYSTEM_NAME eCos)

# specify the cross compiler
CMAKE_FORCE_C_COMPILER(arm-elf-gcc GNU)
CMAKE_FORCE_CXX_COMPILER(arm-elf-g++ GNU)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  /home/alex/src/ecos/install )

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

你可能感兴趣的:(Linux,System,Program,cmake,交叉编译)