A simple example of using a system library in a Zig project. Here, it's the editline
library on OS X
.
Don't take my actual code in main.zig
seriously. This is just a plumbing project, with these goals:
- Can I code up something simple that calls into a system library?
- Can I get it to build?
- When I
zig build run
it, does it seem to be working?
For these goals, it works with zig version 0.11.0-dev. But I've just started looking into Zig/C intergration, and I'm probably doing all sorts of things wrong.
The plumbing details are in build.zig
. Look for
exe.addIncludePath("Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include");
exe.linkSystemLibrary("edit");
- How to use
editline
in a C program on OS X. and search forUsing Editline
. - How to find the include path on OS X. and search for
xcrun
. - Zig build explained. - Out of date, but still good for background.