Can't specify file suffix with Module.linkSystemLibrary()

The Module.linkSystemLibrary() function in the zig build system cannot find system libraries that have a suffix other than .so. For example, I am trying to link my zig project with libFLAC, which appends the library version to the shared object file (such that it is: libFLAC.so.12). I’ve looked through the parameters the function has available to see if it has an override option for this and I’ve also briefly investigating the body of that function to see if there was an obvious alternative method, but I couldn’t find it. Does anyone know the ideal way to go about this?

Without pkg-config, linkSystemLibrary(FLAC, .{})is similar to using the -lFLAC parameter in a C compiler. It is expected that libraries without the .so(or .a) suffix cannot be found.

First, check whether the pc file of this library has been correctly installed.

Or use addObjectFile to explicitly specify the link object path.

1 Like

pkg-config --libs flac must display -lFLAC.
If not, you need to add the package libflac-dev—or something similar depending on the distribution. This installs header files, static archives, and the package configuration flac.pc.

Then use flac for the library name i.e. linkSystemLibary("flac", .{}).

Turns out I was asking the wrong question. Thanks!

1 Like