win10下CMAKE交叉编译ARM-LINUX

WIN10下CMAKE交叉编译ARM64-LINUX

平台准备(接上一篇文章)

win10
cmake
arm-linux-gcc(aarch64-linux-gnu-gcc-7.3.1.exe)
arm-linux-g++(aarch64-linux-gnu-g++.exe)
make
zcu106开发板
vscode编辑器

开始

首先设置好win10下make、cmake、arm-linux-gcc/g++等环境,在shell中查看
win10下CMAKE交叉编译ARM-LINUX_第1张图片
这样环境编装好了,接下来编写CMakeLists.txt
如下:

cmake_minimum_required(VERSION 2.8)

#set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc-7.3.1.exe")
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++.exe")

project(hello_world)

include_directories(inc INC_LIST)

aux_source_directory(src SRC_LIST)

add_executable(hello_world main.c ${SRC_LIST})

这里编写可以参考https://www.cnblogs.com/Trony/p/10952507.html
上面设置了交叉编译器,环境、处理器平台、输出路径等
然后便可以cmake了,这里需要注意,在win10平台下默认生成的是visual stduio2014的版本,需要指定生成标准unix makefile,这里代码如下:

PS C:\Users\Donce Jiang\Desktop\graduate\code\pro> cmake -G "Unix Makefiles" .
-- The C compiler identification is GNU 7.3.1
-- The CXX compiler identification is GNU 7.3.1
-- Check for working C compiler: D:/Software/vivado/SDK/2018.3/gnu/aarch64/nt/aarch64-linux/bin/aarch64-linux-gnu-gcc-7.3.1.exe
-- Check for working C compiler: D:/Software/vivado/SDK/2018.3/gnu/aarch64/nt/aarch64-linux/bin/aar-- 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:/Software/vivado/SDK/2018.3/gnu/aarch64/nt/aarch64-linux/bin/a-- Check for working CXX compiler: D:/Software/vivado/SDK/2018.3/gnu/aarch64/nt/aarch64-linux/bin/aarch64-linux-gnu-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: C:/Users/Donce Jiang/Desktop/graduate/code/pro

然后make

PS C:\Users\Donce Jiang\Desktop\graduate\code\pro> make
Scanning dependencies of target hello_world
[ 33%] Building C object CMakeFiles/hello_world.dir/main.c.o
[ 66%] Linking C executable /bin/hello_world
[100%] Built target hello_world

最后得到hello_world执行代码,这里的hello_world代码如下,打印环境变量
win10下CMAKE交叉编译ARM-LINUX_第2张图片
在开发板上挂载sd卡,并执行hello_world如下:
win10下CMAKE交叉编译ARM-LINUX_第3张图片
大功告成。

你可能感兴趣的:(ARM)