diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-07-05 00:26:27 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2025-02-07 21:54:55 +0100 |
commit | 962f29ba59b3b064d2e6e4d6274f4b4ff09a6412 (patch) | |
tree | abda33f33ede207f9b57a93663bb4a1cc666f8b9 /example-cross-compile-cpp | |
parent | b07a942993efe44e5dbdff8088b0ed87c79fc433 (diff) | |
download | zig-playground-962f29ba59b3b064d2e6e4d6274f4b4ff09a6412.tar.gz zig-playground-962f29ba59b3b064d2e6e4d6274f4b4ff09a6412.zip |
cross: mini cpp cross compile using zig compiler
Diffstat (limited to 'example-cross-compile-cpp')
-rw-r--r-- | example-cross-compile-cpp/.gitignore | 7 | ||||
-rw-r--r-- | example-cross-compile-cpp/Makefile | 18 | ||||
-rw-r--r-- | example-cross-compile-cpp/lin.cc | 5 | ||||
-rw-r--r-- | example-cross-compile-cpp/win.cc | 9 | ||||
-rw-r--r-- | example-cross-compile-cpp/windll.cc | 5 |
5 files changed, 44 insertions, 0 deletions
diff --git a/example-cross-compile-cpp/.gitignore b/example-cross-compile-cpp/.gitignore new file mode 100644 index 0000000..19794fc --- /dev/null +++ b/example-cross-compile-cpp/.gitignore @@ -0,0 +1,7 @@ +*.lib +*.dll +*.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..6c7f234 --- /dev/null +++ b/example-cross-compile-cpp/Makefile @@ -0,0 +1,18 @@ +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-lib -dynamic -target x86_64-windows -lc windll.cc + zig build-exe win.cc -target x86_64-windows -lc windll.lib + file win.exe windll.dll + 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 <stdio.h> + +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..abb0f6d --- /dev/null +++ b/example-cross-compile-cpp/win.cc @@ -0,0 +1,9 @@ +#include <windows.h> +#include <winuser.h> + +__declspec(dllimport) void say(const char*); + +int main() { + say("hello dll"); + MessageBoxA(nullptr, "world", "hello", 0); +} diff --git a/example-cross-compile-cpp/windll.cc b/example-cross-compile-cpp/windll.cc new file mode 100644 index 0000000..890117c --- /dev/null +++ b/example-cross-compile-cpp/windll.cc @@ -0,0 +1,5 @@ +#include <stdio.h> + +__declspec(dllexport) void say(const char* str) { + if (str) puts(str); +} |