From: Pierre Ossman Date: Wed, 21 Jun 2023 11:58:57 +0000 (+0200) Subject: Move where -nodefaultlibs is specified X-Git-Tag: v1.13.90~72 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0319e3e09b9d5e741a78e0591d730ef577c6ecb;p=tigervnc.git Move where -nodefaultlibs is specified The previous method isn't compatible with CMake's try_compile() as it will respect CMAKE_EXE_LINKER_FLAGS, but not CMAKE_C_LINK_EXECUTABLE and friends. This results in the default libraries being completely missing, and the compile test failing. --- diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 1a3bdb46..495b53a1 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -168,8 +168,6 @@ if(BUILD_STATIC) endif() if(BUILD_STATIC_GCC) - # This ensures that we don't depend on libstdc++ or libgcc_s - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -nodefaultlibs") set(STATIC_BASE_LIBRARIES "") if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE) set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -Wl,-Bstatic -lasan -Wl,-Bdynamic -ldl -lpthread") @@ -195,6 +193,7 @@ if(BUILD_STATIC_GCC) else() set(STATIC_BASE_LIBRARIES "${STATIC_BASE_LIBRARIES} -lm -lgcc -lgcc_eh -lc") endif() - set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} ${STATIC_BASE_LIBRARIES}") - set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic ${STATIC_BASE_LIBRARIES}") + # -nodefaultlibs ensures that we don't depend on libstdc++ or libgcc_s + set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_C_LINK_EXECUTABLE} -nodefaultlibs ${STATIC_BASE_LIBRARIES}") + set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -nodefaultlibs -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic ${STATIC_BASE_LIBRARIES}") endif()