#Undefined symbol from translate-c not translating a function body in a single header file

1 messages · Page 1 of 1 (latest)

latent dust
#
    // Used to add SSFN support.
    const ssfn = b.addTranslateC(.{
        .link_libc = false,
        .optimize = optimize,
        .target = target,
        .root_source_file = b.path("dist/vendor/ssfn.c"),
    });
    kernel.root_module.addImport("ssfn", ssfn.createModule());

I am attempting to use a header-only library in my freestanding hobby kernel project.

ZLS accepts the generated code, but I get linker errors when compiling like so:

error: ld.lld: undefined symbol: ssfn_putc
    note: referenced by Console.zig:34 (/home/jacob/Code/eltoro/src/term/Console.zig:34)
    note:               /home/jacob/Code/eltoro/.zig-cache/o/6bf4f95c85ea13bcb49be9d82807ccd2/eltoro.o:(term.Console.init)

Just to confirm, the function is defined further down in the header file, and I renamed it to end in .c thinking that would fix it.

Any help is greatly appreciated!

latent dust
#

Nevermind I just checked

sour marsh
#

so you use translate-c to translate the header. The header only declares the functions, but does not include the code of the function

latent dust
#

Should I instead split the functions into their own compilation unit and link that?

#

I don't know if theres any tricks to do it quicker without duplicate symbol errors etc

sour marsh
#

do you have c source files or do you link any library

latent dust
#

just the one file, to be honest I only need the one symbol so I could just make a C source file with the function definition in there

sour marsh
#

I would do the translate-c like you do and use kernel.addCSourceFile(...) to add the c file.