CMake 在这里有一个教程:
https://github.com/Kitware/CMake/tree/master/Help/guide/tutorial/Complete
我想使用以下命令为 Linux、Mac 和 Windows 交叉构建它:
https://github.com/multiarch/crossbuild
Crossbuild 提供了一个易于使用的 docker 镜像:
https://hub.docker.com/r/multiarch/crossbuild
我用 Debian Bullseye 代替了 stretch 做了一个分叉:
https://hub.docker.com/r/kmturley/crossbuild
我下载了文件并放在一个/src
文件夹中:
https://github.com/kmturley/cmake-multiarch-docker/tree/feature/crossbuild-new
然后我创建了一个 docker-compose 文件,其中包含:
version: '3'
services:
linux:
image: kmturley/crossbuild
environment:
CROSS_TRIPLE: x86_64-linux-gnu
working_dir: /app
command: >
sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/linux &&
cmake --build ./build/linux &&
file ./build/linux/Tutorial"
volumes:
- ./src:/app/src
- ./build:/app/build
mac:
image: kmturley/crossbuild
environment:
CROSS_TRIPLE: x86_64-apple-darwin
working_dir: /app
command: >
sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/mac &&
cmake --build ./build/mac &&
file ./build/mac/Tutorial"
volumes:
- ./src:/app/src
- ./build:/app/build
win:
image: kmturley/crossbuild
environment:
CROSS_TRIPLE: x86_64-w64-mingw32
working_dir: /app
command: >
sh -c "cmake -DUSE_MYMATH=0 -S ./src -B ./build/win &&
cmake --build ./build/win &&
file ./build/win/Tutorial.exe"
volumes:
- ./src:/app/src
- ./build:/app/build
成功运行docker-compose up
时会生成 Linux 和 Windows 二进制文件。但是没有生成 Mac 二进制文件:
./build/linux/Tutorial: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=8ead361bd8494da68a47a4307cff733791777689, for GNU/Linux 3.2.0, not stripped
./build/mac/Tutorial: cannot open `./build/mac/Tutorial' (No such file or directory)
./build/win/Tutorial.exe: PE32+ executable (console) x86-64, for MS Windows
CMakeOutput.log
每个 Docker 映像的文件:
- Linux:https ://gist.github.com/kmturley/61745d5cea04142f4eba029f64a388f9
- Mac:https ://gist.github.com/kmturley/2957ef38929b58e42747a1e2e37dffb5
- 赢:https ://gist.github.com/kmturley/5aa1347959dd7e33c69cca73a45ff788
似乎没有显示任何错误,即使使用cmake --debug-output
.
为什么没有生成 Mac Tutorial 二进制文件?