Skip to content

Commit 0ed3f33

Browse files
authored
Fix order of singlefilehost libarires passed to the linker (#42094)
We give a list of arguments to the linker which includes a list of static objects we want to be linked together and a set of system-wide native libraries they should be dynamically linked against. Some build environments, such as Fedora, use the `--as-needed` linker flag. This makes the linker pay attention to the order in which libraries appear and remove uneeded libararies. When the linker sees this: ld --as-needed -lz staticobject.a It works from left to right and sess that nothing so far depends on libz. The linker removes libz from the set of objects being linked. Then it links staticobject.a, which needs symbols from libz. The linker then complains that it contains an undefined reference. We can fix that by changing the order so that dependencies appear last in the linker command line: ld --as-needed staticobject.a -lz This makes the linker link staticobject.a against libz correctly.
1 parent 1b491f6 commit 0ed3f33

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/installer/corehost/cli/apphost/static/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,12 @@ target_link_libraries(singlefilehost
204204
libhostcommon
205205
${CORECLR_LIBRARIES}
206206

207+
${START_WHOLE_ARCHIVE}
208+
${NATIVE_LIBS}
209+
${END_WHOLE_ARCHIVE}
210+
207211
${ZLIB_LIBRARIES}
208212
${LIBGSS}
209213
${NATIVE_LIBS_EXTRA}
210214

211-
${START_WHOLE_ARCHIVE}
212-
${NATIVE_LIBS}
213-
${END_WHOLE_ARCHIVE}
214215
)

0 commit comments

Comments
 (0)