CMake: Error on unresolved symbols
authorBen Clayton <bclayton@google.com>
Mon, 29 Jun 2020 12:46:26 +0000 (13:46 +0100)
committerBen Clayton <bclayton@google.com>
Mon, 29 Jun 2020 13:57:12 +0000 (14:57 +0100)
Issue: #1484

CMakeLists.txt

index bb5205ea773f7895f745a18ea56bf4e2723a1829..561262a4a3cd4700fd063a94851eebdd00865ef8 100644 (file)
@@ -128,6 +128,9 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
     if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9.0.0")
         add_compile_options(-Werror=deprecated-copy)
     endif()
+
+    # Error if there's symbols that are not found at link time.
+    add_link_options("-Wl,--no-undefined")
 elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
     add_compile_options(-Wall -Wuninitialized -Wunused -Wunused-local-typedefs
                         -Wunused-parameter -Wunused-value  -Wunused-variable)
@@ -138,6 +141,9 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" AND NOT MSVC)
     if(NOT ENABLE_EXCEPTIONS)
         add_compile_options(-fno-exceptions)
     endif()
+
+    # Error if there's symbols that are not found at link time.
+    add_link_options("-Wl,-undefined,error")
 elseif(MSVC)
     if(NOT ENABLE_RTTI)
         string(FIND "${CMAKE_CXX_FLAGS}" "/GR" MSVC_HAS_GR)