CMAKE_CXX_IMPLICIT_LINK_LIBRARIES broken by latest clang on macOS
On macOS 10.12.3, with all the updates applied, CMAKE_CXX_IMPLICIT_LINK_LIBRARIES
contains non-existent library to_library
. I believe this is because the linker output, parse in CMakeParseImplicitLinkInfo.cmake
now contains -lto_library
.
$ /Library/Developer/CommandLineTools/usr/bin/c++ -Wl, -v
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out -lc++ -lSystem /Library/Developer/CommandLineTools/usr/bin/../lib/clang/8.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
A simple fix might be (I don't know all the implication of this, it works on my machine™):
--- CMakeParseImplicitLinkInfo.cmake.fail 2017-04-01 23:15:57.000000000 +0200
+++ CMakeParseImplicitLinkInfo.cmake 2017-04-01 23:18:51.000000000 +0200
@@ -55,6 +55,9 @@
list(APPEND implicit_dirs_tmp ${dir})
string(APPEND log " arg [${arg}] ==> dir [${dir}]\n")
elseif("${arg}" MATCHES "^-l([^:].*)$")
+ if("${arg}" STREQUAL "-lto_library" AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "AppleClang")
+ continue()
+ endif()
# Unix library.
set(lib "${CMAKE_MATCH_1}")
list(APPEND implicit_libs_tmp ${lib})
I found this because I am using CMAKE_CXX_IMPLICIT_LINK_LIBRARIES
to get the libraries when linking C++ code into a Rust project. If there is a better way, I'll take it!