使用cmake交叉编译helloworld

主机环境

cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
 

cmake版本

 cmake --version
cmake version 3.16.3
 

helloworld.c

sice@T:/mnt/lab/cmake_helloworld$ cat helloworld.c
#include <stdio.h>

int main(int argc, char *argv[])
{
        printf("hello world\n");
        return 0;
}

 CMakeLists.txt

sice@T:/mnt/lab/cmake_helloworld$ cat CMakeLists.txt
project(helloworld_project)

cmake_minimum_required(VERSION 3.16)

add_executable(helloworld helloworld.c)

执行cmake命令生成Makefile 

 sice@T:/mnt/lab/cmake_helloworld$ cmake -D CMAKE_C_COMPILER=ntoaarch64-gcc -D CMAKE_CXX_COMPILER=ntoaarch64-g++ .
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Check for working C compiler: /host/linux/x86_64/usr/bin/ntoaarch64-gcc
-- Check for working C compiler: /host/linux/x86_64/usr/bin/ntoaarch64-gcc -- 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: /host/linux/x86_64/usr/bin/ntoaarch64-g++
-- Check for working CXX compiler: /host/linux/x86_64/usr/bin/ntoaarch64-g++ -- 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: /mnt/lab/cmake_helloworld

执行make命令

sice@T:/mnt/lab/cmake_helloworld$ make
Scanning dependencies of target helloworld
[ 50%] Building C object CMakeFiles/helloworld.dir/helloworld.c.o
[100%] Linking C executable helloworld
[100%] Built target helloworld

查看生成的helloworld格式

 sice@T:/mnt/lab/cmake_helloworld$ file helloworld
helloworld: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /usr/lib/ldqnx-64.so.2, BuildID[md5/uuid]=78615a1ab48edd58e97fdbe1f1d9d03e, with debug_info, not stripped

交叉编译成功 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值