I have a Jenkins build server running macOS 10.12.
I am compiling a C++ application using the latest Clang 10 (not AppleClang) with CMake 3.17.
The error I get is:
The C++ compiler
"/Users/XXX/llvm/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
ld: unknown option: -platform_version
clang-10: error: linker failed with exit code 1
This works fine with Clang 9 on the same server and Clang 10 works fine on macOS 10.15 with all other build tools and source files the same (Jenkins runs a clean build each time). It seems to be the combination of Clang 10 and macOS 10.12. Has anything changed between Clang 9 and Clang 10 that would cause this?
I'm invoking CMake like so:
cmake -DCMAKE_OSX_SYSROOT="${macos_sdk}" \
-DCMAKE_C_COMPILER="${llvm_bin}/clang" \
-DCMAKE_CXX_COMPILER="${llvm_bin}/clang++" \
-DCMAKE_OSX_ARCHITECTURES=${architectures} \
-DCMAKE_BUILD_TYPE=${make_build_type} ..
Passing the linker version to Clang via -mlinker-version=305
resolved the issue.
For CMake this can be done like so:
-DCMAKE_CXX_FLAGS="-mlinker-version=305"
Can't help but feel this is a bug.
The linker verison can be obtained via ld -v
on macOS 10.12 where the problem occurs.
A handy bash function to get the ld
version for passing to Clang:
#!/bin/bash
function get_ld_version() {
local info=$( ld -v 2>&1 > /dev/null )
echo "${info}" | perl -wne '/.ld64-(.*?)[^0-9]/ and print "$1\n"'
}
Just in case someone is using CMAKE with CLion IDE which tests both C and C++ compilers, adding -DCMAKE_CXX_FLAGS="-mlinker-version=405"
isn't enough you also need to add "-DCMAKE_C_FLAGS="-mlinker-version=405"
, of course as what @keith mentioned you should use your own linker version
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With