How can you use Zig to compile C++? This isn't one I was aware of
https://andrewkelley.me/post/zig-cc-powerful-drop-in-replace...
HN discussion:
https://news.ycombinator.com/item?id=27872596
previous discussion:
There are some follow-up issues related to zig cc which are still open:
- ...
- support compiling and linking c++ code
Did this change recently? I've tried "zig cc" for C++ before and asked on the Discord and was told it wasn't capable of it. rayga@DESKTOP-88A51E5 MINGW64 ~/Projects/tmp/zig-cc-test
$ zig version
0.9.0-dev.959+f011f1393
rayga@DESKTOP-88A51E5 MINGW64 ~/Projects/tmp/zig-cc-test
$ zig cc test.cpp
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
^~~~~~~~~~
1 error generated.
rayga@DESKTOP-88A51E5 MINGW64 ~/Projects/tmp/zig-cc-test
$ clang test.cpp
rayga@DESKTOP-88A51E5 MINGW64 ~/Projects/tmp/zig-cc-test
$Indeed it also right under "zig cc" in the output for "zig --help" too, if that wasn't clear enough:
$ zig --help
Usage: zig [command] [options]
Commands:
cc Use Zig as a drop-in C compiler
c++ Use Zig as a drop-in C++ compilerhttps://github.com/ziglang/zig/issues/4786
It was closed in March of 2020.
> zig c++ is equivalent to zig cc with an added -lc++ parameter, but I made a separate heading here because I realized that some people are not aware that Zig supports compiling C++ code and providing libc++ too!
You can also mix Zig code and C++ like this:
zig build-exe foo.zig bar.cpp -lc++ -lc