MacOS上的Clang包含以下内容存在问题 [英] Clang on MacOS having problems with its includes

查看:373
本文介绍了MacOS上的Clang包含以下内容存在问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MacOS上从头开始构建Clang,但遇到了问题.

I have built from scratch Clang on MacOS and I am having problems with it.

以下用于配置Clang进行构建:

Used following to configure Clang for building:

cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/opt/clang-12 -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="AArch64;ARM;X86" -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;lldb" ../llvm

这是我的测试程序:

#include <ostream>
#include <algorithm>

int main(int argc, char** argv) {
return 0;
}

  1. 如果使用XCode clang++ -c test.cc

如果使用新的Clang 12(内置) /opt/clang-12/bin/clang++ -c test.cc

ERROR if using new Clang 12 (built) /opt/clang-12/bin/clang++ -c test.cc

In file included from test.cc:2:
In file included from /opt/clang-12/bin/../include/c++/v1/ostream:138:
In file included from /opt/clang-12/bin/../include/c++/v1/ios:214:
In file included from /opt/clang-12/bin/../include/c++/v1/iosfwd:95:
/opt/clang-12/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

根据我要包含的内容,会出现不同的包含错误.

Depending on what I am trying to include I get different include errors.

➜ tests /opt/clang-12/bin/clang++ -v -c test.cc
clang version 12.0.0 (https://github.com/llvm/llvm-project.git b529c5270c99e0ca18e3cbd9a5f50eb0970e560a)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /opt/clang-12/bin
 (in-process)
 "/opt/clang-12/bin/clang-12" -cc1 -triple x86_64-apple-macosx10.15.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cc -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu penryn -debugger-tuning=lldb -target-linker-version 556.6 -v -resource-dir /opt/clang-12/lib/clang/12.0.0 -stdlib=libc++ -internal-isystem /opt/clang-12/bin/../include/c++/v1 -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /opt/clang-12/lib/clang/12.0.0/include -internal-externc-isystem /usr/include -fdeprecated-macro -fdebug-compilation-dir /Users/duddie/Projects/Audio/1voct/1voct_modular/tests -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fcolor-diagnostics -o test.o -x c++ test.cc
clang -cc1 version 12.0.0 based upon LLVM 12.0.0git default target x86_64-apple-darwin19.6.0
ignoring nonexistent directory "/usr/include/c++/v1"
ignoring nonexistent directory "/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/clang-12/bin/../include/c++/v1
 /usr/local/include
 /opt/clang-12/lib/clang/12.0.0/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
In file included from test.cc:2:
In file included from /opt/clang-12/bin/../include/c++/v1/ostream:138:
In file included from /opt/clang-12/bin/../include/c++/v1/ios:214:
In file included from /opt/clang-12/bin/../include/c++/v1/iosfwd:95:
/opt/clang-12/bin/../include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.

  1. 如果Clang 11.0.3(XCode)或Clang 12但针对ARM clang++ -target arm-none-eabi -c test.cc
  2. ,则为错误
  1. ERROR if Clang 11.0.3 (XCode) or Clang 12 but target for ARM clang++ -target arm-none-eabi -c test.cc

test.cc:2:10: fatal error: 'ostream' file not found
#include <ostream>
         ^~~~~~~~~
1 error generated.

有什么主意我在做错什么吗?

Any ideas what am I doing wrong?

推荐答案

将以下内容添加到外壳配置文件~/.bash_profile~/.zsh_profile或通过其他任何方式设置环境变量以供您在其中运行的外壳访问

Add the following to the shell profile file ~/.bash_profile or ~/.zsh_profile or any other way to set environment variable accessible to the shell you're running it in.

export SDKROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk"

在您的macOS/Xcode版本上验证SDK的正确路径.

Verify the correct path to the SDK on your macOS/Xcode version.

重新打开终端(获取文件可能无法可靠工作). 然后再次尝试此命令.

Reopen Terminal (sourcing the file may not work reliably). Then try this command again.

/opt/clang-12/bin/clang++ -c test.cc

命令行工具包将安装macOS系统头文件 在macOS SDK中.使用已安装的工具编译的软件 将在Xcode提供的macOS SDK中搜索标头 在: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk 或位于以下位置的命令行工具: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk取决于哪个 使用xcode-select选择.命令行工具将搜索 默认情况下,SDK用于系统标头.但是,某些软件可能无法 根据SDK正确构建,并要求使用macOS标头 安装在基本系统的/usr/include下.如果你是 此类软件的维护者,我们鼓励您更新您的项目 与SDK配合使用或针对以下问题提交错误报告 阻止您这样做.解决方法是,额外的软件包是 提供的将标题安装到基本系统.在一个 在将来的版本中,将不再提供此软件包.你可以找到 该软件包位于: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

The Command Line Tools package installs the macOS system headers inside the macOS SDK. Software that compiles with the installed tools will search for headers within the macOS SDK provided by either Xcode at: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk or the Command Line Tools at: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk depending on which is selected using xcode-select. The command line tools will search the SDK for system headers by default. However, some software may fail to build correctly against the SDK and require macOS headers to be installed in the base system under /usr/include. If you are the maintainer of such software, we encourage you to update your project to work with the SDK or file a bug report for issues that are preventing you from doing so. As a workaround, an extra package is provided which will install the headers to the base system. In a future release, this package will no longer be provided. You can find this package at: /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

https://developer.apple.com/documentation/xcode-release-notes/xcode-10-release-notes

这篇关于MacOS上的Clang包含以下内容存在问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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