←back to thread

228 points Retro_Dev | 2 comments | | HN request time: 0.418s | source
Show context
90s_dev ◴[] No.44464923[source]
I don't mind breaking changes if I can fix them within a day.

What bothers me with C/C++ is how difficult it is to cross compile a simple Windows + SDL app from inside WSL without MSVC installed.

I've spent weeks on this.

If Zig saves me from that nightmare, and still lets me use C++ libraries, I will gladly switch over to it.

replies(3): >>44464991 #>>44465628 #>>44472217 #
flohofwoe ◴[] No.44464991[source]
You'll have to write C API wrappers around your C++ libraries to access them from Zig, but other then that I can cross-compile my mixed C/C++/Zig projects using Windows APIs like DXGI/D3D/WASAPI with `zig build -Dtarget=x86_64-windows` from a Mac with the vanilla Zig toolchain.

...you don't even need to port anything in your C/C++ project to Zig, just integrate `zig cc` as C/C++ compiler into your existing build system, or port your build system files to build.zig.

replies(2): >>44465041 #>>44465199 #
forrestthewoods ◴[] No.44465199[source]
Wait what. Shouldn’t zig crosscompile C++ just fine?
replies(1): >>44465262 #
1. flohofwoe ◴[] No.44465262[source]
Yes, the C++ code compiles just fine, but to call into C++ APIs from Zig you'll need a C API wrapper (and the same is true for ObjC APIs). Not an issue of course for pure C++ projects when the Zig toolchain is just used for cross-compiling.
replies(1): >>44469187 #
2. forrestthewoods ◴[] No.44469187[source]
Oooh yeah that makes sense.