I have an c file which i would like call from zig. In that file are 2 implementations of matrix vector multiplication, one with avx2 and another with the standart approach. The naive function is easily callable from c, but the “mat_vec_AVX2” causes an error:
“error: ld.lld: undefined symbol: mat_vec_AVX2”
I cant quite get behind why this is occuring and how to fix it.
On another unrelated note, i realized that the compiled c files get cached. Is there some compiler flag to recompile those files ? Because my current method is to delete the cache dir which cant be the intended way.
Double check that you don’t have a C macro that omits the definition of that second function unless a given DEFINE is present, that’s something that happens very often.
You can look at All Your Codebase · GitHub for a few examples on how to integrate C files with macros with the Zig build system.
To get better help you might want to push your project on a publicly accessible repo. You probably have a header file that defines that function conditionally, which makes sense, since AVX is not always available, and that’s what’s tripping you.
There’s a few details that need to be done right for C integration to work and if you don’t know if those were taken care of, the only way you can efficiently communicate your situation is by showing the full code.
It looks like you are @cImporting the C file with the AVX code. The C to Zig translation feature is mainly intended for header declarations, not full implementations. You should probably change your build.zig to compile the C file separately and link it with your executable.
Thank you all a lot for the advice and the help, i ended up using the advice from @permutationlock and that worked. For anyone who has a similar problem and is fighting the build system like me (no hate on the system just hard to understand with the existing documentation), this is the way i have done it: