cmake交叉编译

例子中包含下面三个文件

.

├── CMakeLists.txt

├── CrossCompile.cmake

└── main.cpp

// main.cpp

#include 

int main(){
    std::cout <<  "hello word" << std::endl;
}
# CMakeLists.txt

PROJECT (HELLO)

SET(SRC_LIST main.cpp)
ADD_EXECUTABLE(hello ${SRC_LIST})
# CrossCompile.cmake

set(CMAKE_SYSTEM_NAME Linux)

set(TOOLSCHAIN_PATH  "$ENV{HOME}/ql-ag550qcn-le20-gcc820-v1-toolchain/gcc/")
SET(CMAKE_SYSROOT "$ENV{HOME}/ql-ol-extsdk-ag550qeuabr03a03m8g_ocpu_01.001.07/ql-sysroots")

set(CMAKE_C_COMPILER ${TOOLSCHAIN_PATH}usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${TOOLSCHAIN_PATH}usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-g++)

add_compile_options(-march=armv7-a -marm -mfpu=neon -mfloat-abi=hard)
# 在主机上编译
cmake ..
# 交叉编译
cmake -DCMAKE_TOOLCHAIN_FILE=../CrossCompile.cmake ..

你可能感兴趣的:(linux应用,c++,c语言,开发语言)