From 3e4b9ded0b226ed310b735593f7fb9e372565ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=B8e?= Date: Mon, 10 Dec 2018 15:18:20 +0100 Subject: [PATCH] cmake: clang: Add the runtime library to the link command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building with clang symbols from the runtime library, like __divdi3 were not being resolved. To fix this we add the "library path for the currently used compiler runtime library" to the link path. Signed-off-by: Sebastian Bøe --- cmake/compiler/clang.cmake | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmake/compiler/clang.cmake b/cmake/compiler/clang.cmake index 976efd8fb23..c04370147e3 100644 --- a/cmake/compiler/clang.cmake +++ b/cmake/compiler/clang.cmake @@ -33,5 +33,20 @@ foreach(isystem_include_dir ${NOSTDINC}) list(APPEND isystem_include_flags -isystem ${isystem_include_dir}) endforeach() +execute_process( + COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name + OUTPUT_VARIABLE LIBGCC_FILE_NAME + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + +assert_exists(LIBGCC_FILE_NAME) + +get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY) + +assert_exists(LIBGCC_DIR) + +list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"") +list(APPEND TOOLCHAIN_LIBS gcc) + set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files) string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")