From ed6bd7fd5552afc5b8633b77ba13f04da2168a75 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Fri, 5 Jul 2024 00:26:27 +0200 Subject: cross: mini cpp cross compile using zig compiler --- example-cross-compile-cpp/.gitignore | 5 +++++ example-cross-compile-cpp/Makefile | 17 +++++++++++++++++ example-cross-compile-cpp/lin.cc | 5 +++++ example-cross-compile-cpp/win.cc | 6 ++++++ 4 files changed, 33 insertions(+) create mode 100644 example-cross-compile-cpp/.gitignore create mode 100644 example-cross-compile-cpp/Makefile create mode 100644 example-cross-compile-cpp/lin.cc create mode 100644 example-cross-compile-cpp/win.cc diff --git a/example-cross-compile-cpp/.gitignore b/example-cross-compile-cpp/.gitignore new file mode 100644 index 0000000..3fd3ba4 --- /dev/null +++ b/example-cross-compile-cpp/.gitignore @@ -0,0 +1,5 @@ +*.exe +*.exe.obj +*.pdb +*.elf +*.elf.o diff --git a/example-cross-compile-cpp/Makefile b/example-cross-compile-cpp/Makefile new file mode 100644 index 0000000..6b904a3 --- /dev/null +++ b/example-cross-compile-cpp/Makefile @@ -0,0 +1,17 @@ +riscv64: lin-riscv64 +aarch64: lin-aarch64 +mips64el: lin-mips64el + +lin-%: + zig build-exe lin.cc -target $*-linux-musl -lc --name $*.elf + file $*.elf + qemu-$* $*.elf + +win: + zig build-exe win.cc -target x86_64-windows -lc + file win.exe + wine win.exe + +clean: + git clean -fdx . + diff --git a/example-cross-compile-cpp/lin.cc b/example-cross-compile-cpp/lin.cc new file mode 100644 index 0000000..5d70f91 --- /dev/null +++ b/example-cross-compile-cpp/lin.cc @@ -0,0 +1,5 @@ +#include + +int main() { + puts("hello from cpp main()"); +} diff --git a/example-cross-compile-cpp/win.cc b/example-cross-compile-cpp/win.cc new file mode 100644 index 0000000..b0e701a --- /dev/null +++ b/example-cross-compile-cpp/win.cc @@ -0,0 +1,6 @@ +#include +#include + +int main() { + MessageBoxA(nullptr, "world", "hello", 0); +} -- cgit v1.2.3