Im looking for a way to use dmon which is a file watcher library in C, into my zig code, I follow some tuto but the build API seems to be different now, I dont know how can I import this library into my zig code... :
https://github.com/septag/dmon
#Need help to wrap c code into zig
1 messages · Page 1 of 1 (latest)
Need help to wrap c code into zig
seems like it might be straighforward if its a single header lib. what have you tried and what errors are you getting?
I have follow this : https://medium.com/@eddo2626/lets-learn-zig-4-using-c-libraries-in-zig-5fcc3206f0dc but it's for a C file not a header file, and exe.addIncludePath is not usable like it's shown in the article (the API has changed)
generally for single header libs you'd download it (or have the package manager fetch it) and then include a small c file in your build which defines the necessary c defines and includes the .h file.
are you using build.zig?
if so, exe.addCSourceFile() along with perhaps exe.addIncludePath()
do you have an example somewhere ?
then in you zig app you can @cInclude the .h file - but this time without the impl defines
yes Im using build.zig
yes there are many examples. maybe search here for 'stb_image' which is a common one
this looks like one <#1264256077445202062 message>
this looks like another one https://ziggit.dev/t/using-a-single-header-c-library-from-zig/1913
hope those help. let us know if you have any problems
oh i forgot about this repo i made showing how to use stb_image https://github.com/travisstaloch/zig_stb_image/tree/fix-build
Okay thanks I will try later ;), I need to pass flag at compilation according the OS, for example To build on linux, link with pthread: gcc test.c -lpthread -o test
To build on MacOS, link with CoreServices and CoreFoundation: clang test.c -framework CoreFoundation -framework CoreServices -lpthread -o test
how can I do that with zig ?
addCSourceFile() has a flags param you may be able to use
exe.linkSystemLibrary("pthread")