Zig Version
0.14.0
Steps to Reproduce and Observed Behavior
Given a pkg-config file
prefix=/home/fedora/dev/glslang/install
exec_prefix=/home/fedora/dev/glslang/install
libdir=${exec_prefix}/lib64
includedir=${prefix}/include
Name: glslang
Description: OpenGL and OpenGL ES shader front end and validator
Requires:
Requires.private: SPIRV-Tools
Version:
Libs: -L${libdir} -lglslang -lSPVRemapper
Libs.private: -lSPIRV-Tools -lSPIRV-Tools-opt -lSPIRV-Tools-link
Cflags: -I${includedir}
(at <prefix>/lib64/pkgconfig/glslang.pc)
Which can be exposed by placing it inside a directory on the PKG_CONFIG_PATH env var.
pkg-config --cflags --libs glslang will default to the flags needed for linking as a shared library (only Libs and Cflags) while pkg-config --cflags --libs --static glslang .
export PREFIX="<prefix>"
PKG_CONFIG_PATH="$PREFIX/lib64/pkgconfig" pkg-config --cflags --libs glslang
PKG_CONFIG_PATH="$PREFIX/lib64/pkgconfig" pkg-config --cflags --libs --static glslang
Expected Behavior
https://github.com/ziglang/zig/blob/5ad91a646a753cc3eecd8751e61cf458dadd9ac4/lib/std/Build/Step/Compile.zig#L745C5-L751C6
--static
Compute a deeper dependency graph and use compiler/linker flags intended for
static linking.
--shared
Compute a simple dependency graph that is only suitable for shared linking.
pkg-config must be called with --static to produce a deeper set of transitive dependencies for static linking the archive, however the link_object's preferred link mode is not used to configure pkg-config for linking system libraries. A shared library would represent this as transitive dependencies to be fulfilled at runtime.
As zig does not configure --static to link against system libraries a workaround is to move Libs.private flags to Libs however this leads to overlinking1 of shared libraries. I think the intended behaviour is to provide the --shared or --static flags to pkg-config depending on the targeted link mode to support this.
Zig Version
0.14.0
Steps to Reproduce and Observed Behavior
Given a pkg-config file
(at
<prefix>/lib64/pkgconfig/glslang.pc)Which can be exposed by placing it inside a directory on the
PKG_CONFIG_PATHenv var.pkg-config --cflags --libs glslangwill default to the flags needed for linking as a shared library (onlyLibsandCflags) whilepkg-config --cflags --libs --static glslang.Expected Behavior
https://github.com/ziglang/zig/blob/5ad91a646a753cc3eecd8751e61cf458dadd9ac4/lib/std/Build/Step/Compile.zig#L745C5-L751C6
pkg-configmust be called with--staticto produce a deeper set of transitive dependencies for static linking the archive, however the link_object's preferred link mode is not used to configurepkg-configfor linking system libraries. A shared library would represent this as transitive dependencies to be fulfilled at runtime.As zig does not configure
--staticto link against system libraries a workaround is to moveLibs.privateflags toLibshowever this leads to overlinking1 of shared libraries. I think the intended behaviour is to provide the--sharedor--staticflags to pkg-config depending on the targeted link mode to support this.Footnotes
https://wiki.mageia.org/en/Overlinking_issues_in_packaging ↩