New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig build system doesn't link C against system libraries #550

Hejsil opened this Issue Oct 19, 2017 · 1 comment


None yet
2 participants

Hejsil commented Oct 19, 2017

With the following build.zig

const Builder = @import("std").build.Builder;

pub fn build(b: &Builder) {
    const exe = b.addCExecutable("main");
    exe.addCompileFlags([][]const u8 {


Running zig build --verbose gives the following:

cc -c /home/jc/Documents/xml_test/src/main.c -o /home/jc/Documents/xml_test/zig-cache/src/main.c.o -std=c99 -I/usr/include/libxml2
cc /home/jc/Documents/xml_test/zig-cache/src/main.c.o -o /home/jc/Documents/xml_test/main -Wl,-rpath,/home/jc/Documents/xml_test/zig-cache -rdynamic
/home/jc/Documents/xml_test/zig-cache/src/main.c.o: In function `main':
main.c:(.text+0x1a): undefined reference to `xmlReaderForFile'
collect2: error: ld returned 1 exit status
Process cc exited with error code 1

As far as I can see, Zig didn't include -lxml2 when linking the object file

@andrewrk andrewrk added the bug label Oct 19, 2017

@andrewrk andrewrk modified the milestone: 0.2.0 Oct 19, 2017

@andrewrk andrewrk closed this in b3d12d2 Oct 21, 2017


This comment has been minimized.


andrewrk commented Oct 21, 2017

Thank you for the report, and apologies for the trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment