Still getting the same error, just moved to the C file:
zig build-exe init-exe Debug native: error: error(compilation): clang failed with stderr: In file included from (root)\src\enet_impl.c:2:
(root)\libs/enet.h:4978:23: error: use of undeclared identifier 'CLOCK_MONOTONIC'
Are you linking libc when building Zig? When building against the C standard library you need to add the -lc flag to calls to zig build-exe or add something along the lines of exe.linkLibC() to your build.zig.
The CLOCK_MONOTONIC definition should be included from time.h so I expect that the undeclared identifier comes from cInclude not knowing how to find time.h.
Oh, of course. Hmm, but as it it is included inside enet.h shouldn’t an extra include not be needed? The library seems to build and work fine for me with just a single cInclude("enet.h"). I am on x86_64-linux though.
Good to see that you found a solution. A lot of C/C++ projects have these kinds of quirks to them. Tiny inconsistencies between different platforms, things getting occasionally out of sync, etc.
The only solution is just to learn how to deal with them systematically… or to wait for somebody else to create a build.zig file and package the library for you.
Welcome to the bleeding edge of systems programming!
Although this is not exactly a flaw with the language, but a missing piece in the toolchain. Without Zig you would have had to procure the entirety of the required headers and libs on your own, and in this case you got most of them, just not all.
If you look at the thread on GH there’s a PR that aims to solve this problem, so a kind contributor has already done some work to solve your problem, it just hasn’t been merged yet.
So my suggestion is to subscribe to that PR and wait for it to be merged.
As an optional step, you could also check out that branch, build Zig from it, and use the PR even without it being merged, the problem in this case is that it seems to have incurred in some regressions (CI is red on most hosts), so you probably won’t get a working source tree right away, but it might also be that those are easy fixes, so it might prove a viable path afterall.