Static Libraries Not Propagating System Include/Library Paths to Consuming Executables

This issue I just created does a good job of describing what I ran into:

But, the TLDR:

  • Create a static library in build.zig, link in some “system” library using:
    static_lib.addSystemIncludePath(.{ .cwd_relative = "/some/system/path/some_lib_folder/include" });
    static_lib.addLibraryPath(.{ .cwd_relative = "/some/system/path/some_lib_folder/lib" });
    static_lib.linkSystemLibrary("some_lib");
  • Link against this library in your application like so:
exe.linkLibrary(static_lib);
  • Observe that you get an error from Zig looking like:
error: error: unable to find dynamic system library 'some_lib' using strategy 'paths_first'. searched paths:
  /usr/local/lib64/libsome_lib.so
  /usr/local/lib64/libsome_lib.a
  /usr/local/lib/libsome_lib.so
  /usr/local/lib/libsome_lib.a
  /usr/lib/x86_64-linux-gnu/libsome_lib.so
  /usr/lib/x86_64-linux-gnu/libsome_lib.a
  /lib64/libsome_lib.so
  /lib64/libsome_lib.a
  /lib/libsome_lib.so
  /lib/libsome_lib.a
  /usr/lib64/libsome_lib.so
  /usr/lib64/libsome_lib.a
  /usr/lib/libsome_lib.so
  /usr/lib/libsome_lib.a
  /lib/x86_64-linux-gnu/libsome_lib.so
  /lib/x86_64-linux-gnu/libsome_lib.a
  • Observe that the path you provided to your static library in static_lib.addLibraryPath(() is nowhere to be found…

This can’t be intended behavior, right? Shouldn’t the static library propagate its library/system include paths up to an executable that’s linking against it?