Incorrect archiver Command Line Call When Linking a Static "System" Library to another Static Library #20476
Labels
bug
Observed behavior contradicts documented or intended behavior
zig build system
std.Build, the build runner, `zig build` subcommand, package management
Milestone
Zig Version
0.13.0
Steps to Reproduce and Observed Behavior
High Level Summary
Zig appears to be erroneously passing
.a
files directly toar
when the following scenario takes place:addLibraryPath()
andlinkSystemLibrary
/linkSystemLibrary2
This is possibly the root cause of this issue:
#13177
Detailed Info
Observe the example repo here:
https://github.com/haydenridd/zig-static-system-library-bug
In this example we have the following:
In
build.zig
there is a booleansystem_library_method
that controls two different types of building this executable that should be equivalent.When
false
:This behaves as expected, the build calls (common flags truncated for readability) look like:
There's a lot here, but the important part to pay attention to is the
ar
call that archives "static_lib" into a library:Now compare this to the behavior when
system_library_method = true
:libsys_lib.a
copied from the previous output intoprebuilt_sys_lib
folderaddLibraryPath()
andlinkSystemLibrary2
calls respectivelyThis produces the following warning from
ld.lld
:Examining the build calls, the culprit is this:
Zig is passing
libsys_lib.a
to the archiver, which LLVM is rightfully complaining about, as that isn't valid. However, the program still works because Zig also correctly passes the link dependencylibsys_lib.a
to the executable:Expected Behavior
.a
files directly to the archiver (ar
)The text was updated successfully, but these errors were encountered: