Я использую Clang 10 (не AppleClang) в macOS 10.15 и пытаюсь установить связь с LLD, указав -fuse-ld=lld
в флагах CMake CMAKE_EXE_LINKER_FLAGS
.
Однако я получаю следующую ошибку, когда Я пытаюсь использовать LLD:
The C++ compiler
"/Users/XXX/llvm/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
ld64.lld: warning: ignoring unknown argument: -platform_version
ld64.lld: warning: ignoring unknown argument: -search_paths_first
ld64.lld: warning: ignoring unknown argument: -headerpad_max_install_names
ld64.lld: warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
ld64.lld: error: Unable to find library for -lc++
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [cmTC_0d561] Error 1
make: *** [cmTC_0d561/fast] Error 2
Вот моя программа:
#include <iostream>
#include <cstdlib>
int main()
{
std::cout << "Hello World!" << std::endl;
return EXIT_SUCCESS;
}
Вот мой файл CMakeLists.txt:
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
project(test VERSION 2.0 LANGUAGES CXX)
add_executable(testprog "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
Вот мой bash скрипт для запуска CMake:
#!/bin/bash
root="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
sys_root="/Users/XXX/macOS-sdks/MacOSX10.13.sdk"
cmake_bin_path="/Applications/CMake.app/Contents/bin"
llvm_bin="/Users/XXX/llvm/bin"
function add_search_path() {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
add_search_path $cmake_bin_path
add_search_path $llvm_bin
cd "${root}/build"
cmake -DCMAKE_OSX_SYSROOT=${sys_root} \
-DCMAKE_C_COMPILER="${llvm_bin}/clang" \
-DCMAKE_CXX_COMPILER="${llvm_bin}/clang++" \
-DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" \
-DCMAKE_OSX_ARCHITECTURES=x86_64 \
-DCMAKE_BUILD_TYPE=Debug ..
cores=`sysctl -n hw.physicalcpu`
cmake --build "${root}/build" --target all -- -j ${cores}
./testprog