#How to use an already built Zig library (libfoo.a) inside a Zig project?

1 messages · Page 1 of 1 (latest)

vague igloo
#

you need to define the exported symbols in libfoo as extern in main

dusty verge
#

I have a function in foo.zig

export fn add(a: i32, b: i32) i32 {
    return a + b;
}

then add in main.zig

extern fn add(a: i32, b: i32) i32;

If that is what you meant, I tried it and gives me the following error
error: ld.lld: undefined symbol: add

upper lagoon
#

what command are you using to compile

dusty verge
upper lagoon
#

no i mean to compile main.zig

#

when you compile main.zig you have to add libfoo.a to your list of targets like this: zig build-exe main.zig libfoo.a

dusty verge
#

Yes, it was stupid of me to forget this

upper lagoon
#

🙂