Linking System Libraries with unusual path

Hi,

I would like to link lapacke to my zig code, so I added

exe.linkSystemLibrary2("lapacke", .{ .preferred_link_mode = .static });
exe.linkSystemLibrary2("lapack", .{ .preferred_link_mode = .static });
exe.linkSystemLibrary2("gfortran", .{ .preferred_link_mode = .static });
exe.linkLibC();

To my build.zig. However, the libgfortran, which is required by lapack on my ubuntu machine, is located in /usr/lib/gcc/x86_64-linux-gnu/13/libgfortran.a which is not searched by the linker.
I tried to add the library path with

exe.addLibraryPath(.{ .path = "/usr/lib/gcc/x86_64-linux-gnu/13/" });

but I get the error, that LazyPath has no member “path”. How can I add the path to be searched?

Thanks.

Edit: So I just found out, that the addLibraryPath ist not required if the linking of lapacke is dynamic. But if you know how to solve this statically, help would be much appreciated.

I think you could use:

exe.addLibraryPath(.{ .cwd_relative = "/usr/lib/gcc/x86_64-linux-gnu/13/" });

An absolute path or a path relative to the current working directory of the build runner process. This is uncommon but used for system environment paths such as --zig-lib-dir which ignore the file system path of build.zig and instead are relative to the directory from which zig build was invoked. Use of this tag indicates a dependency on the host system.

But I think a better way may be to use zig build --help:

System Integration Options:
  --search-prefix [path]       Add a path to look for binaries, libraries, headers
1 Like

Thank you,
The path is successfully searched. However, I get a bunch of missing symbols. Guess, I will go with a dynamically linked binary.