Homebrew的LLVM@12在macOS上出现“致命错误:未找到’bits/stdc++.h’文件”

huangapple go评论61阅读模式
英文:

Homebrew's LLVM@12 "fatal error: 'bits/stdc++.h' file not found" on macOS

问题

  1. 安装 LLVM brew install llvm@12

  2. 创建 dest.cpp

#include <bits/stdc++.h>
  // 代码
  1. 运行 /opt/homebrew/opt/llvm@12/bin/clang++ dest.cpp -o dest 时,出现错误:
fatal error: 'bits/stdc++.h' 文件未找到
  1. 将包含 stdc++.h 文件的 bits 目录添加到路径中:/opt/homebrew/Cellar/llvm@12/12.0.1_1/Toolchains/LLVM12.0.1.xctoolchain/usr/include,但仍然出现相同的致命错误。

  2. 将其添加到 /opt/homebrew/Cellar/llvm@12/12.0.1_1/include,但结果仍然相同。

PS. stdc++.h 文件是正确的,因为当我将其添加到 /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include 时,我成功使用它,但是当我将其添加到 llvm@12 时不起作用。

我必须在这里使用 stdc++.h,因为我的工作是测试数百个代码,其中大多数都使用 stdc++.h,更改头文件以符合它们确切需求对我来说太困难了。

问题出在哪里? 在运行 /opt/homebrew/opt/llvm@12/bin/clang++ 时是否可能拥有 stdc++.h?

英文:

1.Install LLVM brew install llvm@12

2.create dest.cpp

#include &lt;bits/stdc++.h&gt;
  // code

3.when i run /opt/homebrew/opt/llvm@12/bin/clang++ dest.cpp -o dest, i get:

fatal error: &#39;bits/stdc++.h&#39; file not found

1.i add directory bits which contains a file stdc++.h to path : /opt/homebrew/Cellar/llvm@12/12.0.1_1/Toolchains/LLVM12.0.1.xctoolchain/usr/include, i get the same fatal

2.i add it to /opt/homebrew/Cellar/llvm@12/12.0.1_1/include too, but result is the same

PS.the stdc++.h file is correct, because I use it successful when I add it /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include, but it does not work when i add it to llvm@12

I have to have stdc++.h here because my work is to test hundreds of codes and most of them have the stdc++.h, it is too difficult for me to change the headers to what they exactly need.

what is the trouble? is it possible to have stdc++.h while I run /opt/homebrew/opt/llvm@12/bin/clang++?

答案1

得分: 2

bits/stdc++.h 是一个特定于 libstdc++ 的头文件。

在 Mac OS 上,标准库是 libc++,它没有这个文件(这是 libstdc++ 的一个非标准实现细节)。

如果您不愿意/无法更改源文件,我可以考虑两个选项:

  • 在您的 Mac 上安装 libstdc++。 这可能有效,但我认为 Mac OS 不是 libstdc++ 支持的平台。

  • 创建您自己的文件 stdc++.h,并将其放入名为 bits 的文件夹中,然后指定 clang 使用它。 您需要弄清楚要将什么内容放入该文件。

英文:

bits/stdc++.h is a libstdc++-specific header file.

On Mac OS, the standard library is libc++, which does not have that file.
(it's a non-standard implementation detail of libstdc++).

If you are unwilling/unable to change your source files, I can think of two options:

  • Install libstdc++ on your Mac. This will probably work, but (I believe) that Mac OS is not a supported platform for libstdc++.

  • Create your own file stdc++.h and put it in a folder named bits and point clang at it. You'll need to figure out what to put into the file.

答案2

得分: 0

尝试使用Clang++的-I /path/to/headerfile选项,让编译器知道在哪里查找未在其标准搜索目录中找到的头文件:

clang++ dest.cpp -o dest -I /path/to/bits

英文:

Try using -I /path/to/headerfile option with Clang++ to let the compiler know where else to search for the header files that are not found in its standard search directories:

clang++ dest.cpp -o dest -I /path/to/bits

huangapple
  • 本文由 发表于 2023年4月20日 03:41:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058253.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定