#Need help to wrap c code into zig

1 messages · Page 1 of 1 (latest)

spice quartz
spice quartz
#

Need help to wrap c code into zig

thin shoal
#

seems like it might be straighforward if its a single header lib. what have you tried and what errors are you getting?

spice quartz
thin shoal
#

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.

spice quartz
#

Okay thanks and how to include the c file during the build ?

#

that is my problem

thin shoal
#

are you using build.zig?

#

if so, exe.addCSourceFile() along with perhaps exe.addIncludePath()

spice quartz
#

do you have an example somewhere ?

thin shoal
#

then in you zig app you can @cInclude the .h file - but this time without the impl defines

spice quartz
#

yes Im using build.zig

thin shoal
#

yes there are many examples. maybe search here for 'stb_image' which is a common one

#

hope those help. let us know if you have any problems

spice quartz
#

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 ?

thin shoal
#

addCSourceFile() has a flags param you may be able to use

wanton iris