#[solved] Automated access to C code with extern instead of translate-c. Is it possible?
1 messages · Page 1 of 1 (latest)
making automated extern fn is what translate-c does
translate-C expands macros and translates the body of the functions into export not extern
#proof:
Source .h:
https://github.com/heysokam/cvulkan/blob/b8701b600560f890385da7cf2951e38a67eea9f9/src/cvulkan/device.h#L65
Source .c: https://github.com/heysokam/cvulkan/blob/b8701b600560f890385da7cf2951e38a67eea9f9/src/cvulkan/device/physical.c#L49
Result: https://github.com/heysokam/cvulkan/blob/b8701b600560f890385da7cf2951e38a67eea9f9/src/ffi/zig/src/cvulkan.zig#L18340
headers generally don't contain the source they only contain the signature (at least not without a impl flag)
which means it will generate extern functions
how would the c library be able to import the header if your translate-c zig also exports the symbol it cant (if it linked to the zig module)
you also couldnt import the header into multiple files in c (or if its imported multiple times without a header guard / pragma once)
extern means you aren't looking for the source anyways so why are you including it in that translate-c arg? just add the C source file in a separate step / link against the already generated lib (not in a translate-c part)
I assume that the only case that doesnt cover is macros which I dont have an answer for
I found the issue
I was translating a file that had #define cvk_Implementation implementation defined,
and apparently translate-c automatically generates with export, instead of extern, when it finds the declaration in the file being translated