#Info on how I should be using C in Zig?

1 messages · Page 1 of 1 (latest)

tender spire
#

I know that @cImport is being deprecated/removed, but I can't find any articles or anything from zig on how I am supposed to use C without @cImport. Any guidance? Even just a link covering this would be fine

upper flame
#

the "replacement" for it is to use addTranslateC in the build.zig, then create a module with that translated file as the root, and then add it as a module import whereever you need.
this solves the annoying issue people often face where you have cImport called multiple times, and is just better suited to be in the build system

summer palm
#

eg,

  .root_source_file = <path to .h>,
  .target = target,
  .optimize = .optimize,
});
exe.root_module.addImport("header", c_header.createModule());```

Then in your Zig code:
```const c = @import("header");```
tender spire
#

tyvm ❤️

tender spire
queen warren