1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > cmake linux 交叉编译 [CMake]CMake设置arm-linux-gcc交叉编译器

cmake linux 交叉编译 [CMake]CMake设置arm-linux-gcc交叉编译器

时间:2018-09-03 17:20:33

相关推荐

cmake linux 交叉编译 [CMake]CMake设置arm-linux-gcc交叉编译器

标签: cmake 交叉编译器 arm-linux-gcc 分类: 开发工具/开发环境

主机:Ubuntu18.04

交叉编译器:arm-linux-gcc

CMake在ubuntu系统下默认使用系统的gcc、g++编译器,编译arm下的程序要使用arm-linux-gcc,须要对CMake进行设置(经过在CMakeLists.txt中指定交叉编译器的方法)。

在CMakeLists.txt一开始加入相关设置:html

告知当前使用的是交叉编译方式,必须配置

SET(CMAKE_SYSTEM_NAME Linux)linux

指定C交叉编译器,必须配置

或交叉编译器使用绝对地址

SET(CMAKE_C_COMPILER “arm-linux-gcc”)ubuntu

指定C++交叉编译器

SET(CMAKE_CXX_COMPILER “arm-linux-g++”)ide

不必定须要设置

指定交叉编译环境安装目录…

SET(CMAKE_FIND_ROOT_PATH “…”)工具

历来不在指定目录下查找工具程序

SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)开发工具

只在指定目录下查找库文件

SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)ui

只在指定目录下查找头文件

SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)this

1.cmake 官网教程 /cmake/help/v3.2/manual/cmake-toolchains.7.html?highlight=cmake_c_compiler#cross-compiling-for-linuxspa

2.Cross Compilingorm

If cmake(1) is invoked with the command line parameter-DCMAKE_TOOLCHAIN_FILE=path/to/file, the file will be loaded early to setvalues for the compilers.The CMAKE_CROSSCOMPILING variable is set to true when CMake iscross-compiling.

Cross Compiling for Linux

A typical cross-compiling toolchain for Linux has content suchas:

set(CMAKE_SYSTEM_NAME Linux)

set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_SYSROOT /home/devel/rasp-pi-rootfs)

set(CMAKE_STAGING_PREFIX /home/devel/stage)

set(tools /home/devel/gcc-4.7-linaro-rpi-gnueabihf)

set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)

set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)

set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

The CMAKE_SYSTEM_NAME is the CMake-identifier of the target platformto build for.

The CMAKE_SYSTEM_PROCESSOR is the CMake-identifier of the target architectureto build for.

The CMAKE_SYSROOT is optional, and may be specified if a sysrootis available.

The CMAKE_STAGING_PREFIX is also optional. It may be used to specifya path on the host to install to. The CMAKE_INSTALL_PREFIX is alwaysthe runtime installation location, even when cross-compiling.

The CMAKE__COMPILER variables may be set to full paths, or tonames of compilers to search for in standard locations. In cases where CMake doesnot have enough information to extract information from the compiler, theCMakeForceCompiler module can be used to bypass some of the checks.

CMake find_* commands will look in the sysroot, and the CMAKE_FIND_ROOT_PATHentries by default in all cases, as well as looking in the host system root prefix.Although this can be controlled on a case-by-case basis, when cross-compiling, itcan be useful to exclude looking in either the host or the target for particularartifacts. Generally, includes, libraries and packages should be found in thetarget system prefixes, whereas executables which must be run as part of the buildshould be found only on the host and not on the target. This is the purpose ofthe CMAKE_FIND_ROOT_PATH_MODE_* variables.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。