#compile C dll and include zig headers
1 messages · Page 1 of 1 (latest)
you also havent really been very clear with what you want
you want to call a zig function from C?
https://ziglearn.org/chapter-4/#calling-conventions
this should explain most of it
Chapter 4 - Learn about how the Zig programming language makes use of C code. This tutorial covers C data types, FFI, building with C, translate-c and more!
yes
it does not
that works if what youre building from c is an executable
it does, it says how to create a zig function with a C callconv
then you can just call that from C
link against the zig code
How do I configure build.zig to make this happen?
how do you build your C and Zig code?
based off of that build.zig
const Builder = @import("std").build.Builder;
pub fn build(b: *Builder) void {
const lib = b.addSharedLibrary("mathtest", "mathtest.zig", b.version(1, 0, 0));
const exe = b.addExecutable("test", null);
exe.addCSourceFile("test.c", &[_][]const u8{"-std=c99"});
exe.linkLibrary(lib);
exe.linkSystemLibrary("c");
b.default_step.dependOn(&exe.step);
const run_cmd = exe.run();
const test_step = b.step("test", "Test the program");
test_step.dependOn(&run_cmd.step);
}```
okay then they should already be linked into the same executable, no?
you can just create a header file containing the right function declaration for the C code to call it
is there a way to do that automatically?
i think theres a way to tell it to emit headers, check the cli flags and docs
when i use emit_h it tries to import zig.h
yea this doesnt really explain anything
it seems rather outdated
its only slightly outdated, only the code samples need a couple changes
the rest of it seems correct
even fixing it, it doesnt work
this still fails to compile
doesnt work how
.
if i dont use emit_h, the header just isnt there for the c file
https://github.com/ziglang/zig/issues/15575
known issue
Zig Version 0.10.1 and 0.11.0-dev.2969+855493bb8 Steps to Reproduce and Observed Behavior Testing out ziglang.org/learn build test on mathtest.zig and receiving errors both on 0.10.1 and the master...
seems to just be broken
excellent