Clang 10无法在MacOS 10.12上将C ++应用程序与CMake链接 [英] Clang 10 fails to link C++ application with CMake on macOS 10.12

查看:317
本文介绍了Clang 10无法在MacOS 10.12上将C ++应用程序与CMake链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台运行macOS 10.12的Jenkins构建服务器.

I have a Jenkins build server running macOS 10.12.

我正在使用带有CMake 3.17的最新Clang 10(不是AppleClang)来编译C ++应用程序.

I am compiling a C++ application using the latest Clang 10 (not AppleClang) with CMake 3.17.

我得到的错误是:

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

这在同一台服务器上的Clang 9上运行良好,而在所有其他构建工具和源文件相同的情况下,Clang 10在macOS 10.15上运行良好(Jenkins每次运行全新构建).它似乎是Clang 10和macOS 10.12的组合.在Clang 9和Clang 10之间有什么改变会导致这种情况吗?

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?

我正在这样调用CMake:

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} ..

推荐答案

通过-mlinker-version=305将链接器版本传递给Clang解决了该问题.

Passing the linker version to Clang via -mlinker-version=305 resolved the issue.

对于CMake,可以这样操作:

For CMake this can be done like so:

-DCMAKE_CXX_FLAGS="-mlinker-version=305"

不禁觉得这是一个错误.

Can't help but feel this is a bug.

可以在出现问题的macOS 10.12上通过ld -v获得链接器版本.

The linker verison can be obtained via ld -v on macOS 10.12 where the problem occurs.

一个方便的bash函数,用于获取ld版本以传递给Clang:

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"'
}

这篇关于Clang 10无法在MacOS 10.12上将C ++应用程序与CMake链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆