在windows上,用cmake 交叉编译arm程序

在windows上,用cmake 交叉编译arm程序。生成器用nijia(或用MinGW,此时, cmake执行时,指定生成器为 -G “MinGW Makefiles”, 编译用make).

CMakeLists.txt

cmake_minimum_required(VERSION 3.6)

project(testApp)

file(WRITE main.cpp "int main(void) { return 0; }")

set(testApp "testApp")

list(
    APPEND testApp_sources
        main.cpp
)

add_executable(
    ${testApp}
    ${testApp_sources}
)

toolchain.cmake


set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER "arm-none-eabi-gcc.exe")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++.exe")

set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs" CACHE INTERNAL "")

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)

在cmd 执行

cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE:PATH="..\toolchain.cmake" ..

-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-gcc.exe
-- Check for working C compiler: D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-g++.exe
-- Check for working CXX compiler: D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: D:/work/clip/code/test/build

编译

>ninja
[2/2] Linking CXX executable testApp

说下遇到的问题,出现以下错误:

D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-gcc

  is not a full path to an existing compiler tool.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.

原因是在window下,要把后缀也写上。下面是不行的。

set(CMAKE_C_COMPILER "D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-gcc")

改成

set(CMAKE_C_COMPILER "D:/sigmastar/flythings/sdk/platforms/ssd/toolchain/bin/arm-pc-linux-gnueabihf-gcc.exe")

您的支持是我持续创作的动力!
在这里插入图片描述

  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值