主机环境
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
交叉编译成功