From: Omair Majid Date: Thu, 17 Sep 2020 14:26:52 +0000 (-0400) Subject: Fix order of singlefilehost libarires passed to the linker (#42094) X-Git-Tag: submit/tizen/20210909.063632~5447 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ed3f3311e4d07cf6840b78c32055ab1b16d092c;p=platform%2Fupstream%2Fdotnet%2Fruntime.git 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. --- diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt index 85ea6ff..e6369f6 100644 --- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt +++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt @@ -204,11 +204,12 @@ target_link_libraries(singlefilehost libhostcommon ${CORECLR_LIBRARIES} + ${START_WHOLE_ARCHIVE} + ${NATIVE_LIBS} + ${END_WHOLE_ARCHIVE} + ${ZLIB_LIBRARIES} ${LIBGSS} ${NATIVE_LIBS_EXTRA} - ${START_WHOLE_ARCHIVE} - ${NATIVE_LIBS} - ${END_WHOLE_ARCHIVE} )