4

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} ..
keith
  • 5,122
  • 3
  • 21
  • 50

2 Answers2

7

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"'
}
keith
  • 5,122
  • 3
  • 21
  • 50
  • Have you considered adding this as an answer to your [other question](https://stackoverflow.com/questions/60944732/using-fuse-ld-lld-with-clang-on-macos)? I think the current accepted answer there is somewhat misleading. – fakedad Jan 03 '21 at 00:35
  • @fakedad, the accepted answer to [my other question](https://stackoverflow.com/questions/60944732/using-fuse-ld-lld-with-clang-on-macos) does answer the other question. My other question was the wrong question to have asked to solve the problem here. – keith Jan 03 '21 at 17:10
2

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

jimmy mac
  • 31
  • 5