我最近通过brew包管理器将我的M1 Mini Mac上的Clang编译器从Clang 17.0.6升级到Clang 18.1.5。我有几个测试程序具有与 Clang 17.0.6 配合良好的
std::println
。现在使用 Clang 18.1.5 我收到以下错误消息:
Undefined symbols for architecture arm64:
"std::__1::__is_posix_terminal(__sFILE*)", referenced from:
std::__1::__print::__is_terminal[abi:ne180100](__sFILE*) in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)`
我不确定 Clang 18.1.6 是否删除了对
std::println
或 <print>
头库的支持?我尝试搜索发行说明,但没有找到与此主题相关的任何内容。顺便说一句,我在我的 CMakeLists.txt
中将 C++ 标准指定为 23
这是正确的 libc++ 的链接器问题。我不确定brew更新发生了什么,它改变了安装位置而没有符号链接。我已经通过brew重新安装了llvm并收到以下消息:
To use the bundled libc++ please add the following LDFLAGS:
LDFLAGS="-L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++"
llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have llvm first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc
For compilers to find llvm you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
因此,我已将以下行添加到我的 CMakeLists.txt 中,然后一切都按预期工作
std::println
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/opt/llvm/lib/c++ -Wl,-rpath,/opt/homebrew/opt/llvm/lib/c++")