c++ cmake 跨平台编译
https://zhuanlan.zhihu.com/p/661285478
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(hello1)
set(CMAKE_C_COMPILE "aarch64-poky-linux-gcc")
set(CMAKE_CXX_COMPILE "aarch64-poky-linux-g++")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
add_executable(hello main.cpp)
main.cpp
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout << "hellow world !!\r\n" << endl;
return 0;
}
使能编译器指令
source /opt/poky/3.1.20/environment-setup-aarch64-poky-linux
cmake -Bbuild ./
cd build/
make
ls
file ./hello
./hello: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-aarch64.so.1, for GNU/Linux 3.14.0, BuildID[sha1]=69488a8568a8995d10a890a6a9717fffce3b7dfd, with debug_info, not stripped

浙公网安备 33010602011771号