我怎样才能在xcode中包含<bits/stdc ++>

Oma*_*mar 19 c++ macos xcode

我试图在我的c ++代码中包含头文件位/ stdc ++,但似乎编译器不支持它,有没有办法让它工作?

我使用OS X Yosemite 10.10.2和Xcode 6.1.1

Rez*_*eza 20

你可以通过从这里复制stdc ++.h文件来做到这一点:https: //gist.github.com/reza-ryte-club/97c39f35dab0c45a5d924dd9e50c445f

然后,您可以将文件包含在c ++文件中,如下所示:

 //suppose the file is in your home folder, here my username is reza
 #include "/Users/reza/stdc++.h"
Run Code Online (Sandbox Code Playgroud)

  • 这是一个糟糕的建议,包含完整路径的哈希是一种残暴的行为 (8认同)

小智 12

Mac OS X 10.9+不再使用GCC/libstdc ++,而是使用libc ++和Clang.

在XCode 6.0.1更新之后,标题现在位于:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1

所以,从这里获取stdc ++.h文件,然后在上面的长地址中创建bits目录,并将文件stdc ++.h复制到bits目录.

  • 至少,不要将其称为“bits/stdc++.h”。这是 libstdc++ 中实现头的名称。称之为“myHeaderWithAllOfTheStdlib”或其他名称 (2认同)

Rav*_*mar 9

在将 bits/stdc++.h 添加到您的 mac os 平台之前,首先要弄清楚包含文件的位置。找出在您的 mac 环境中使用的包含文件。

  • 在终端中运行此命令:

    回声"" | gcc -xc - -v -E

这将提供您平台中 gcc 环境的详细信息

Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/......."
ignoring nonexistent directory 
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory 
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include
 /Library/Developer/CommandLineTools/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include


/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 361 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
Run Code Online (Sandbox Code Playgroud)
  • 转到包含路径。例如:/usr/local/include 创建一个 bits 文件夹并添加stdc++.h文件。


Bre*_*dan 8

你不能.X-Code使用带有Clang的LLVM工具链作为编译器,而<bits/stdc++>特定于GNU编译器工具链.

其次,你不应该首先使用那个标题,正如其他人所说的那样.

  • 但是通过在“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/”中创建一个文件夹,我可以添加stdc++.h和有效 (3认同)

小智 5

因为,bits/stdc ++是GNU GCC扩展,而OSX使用clang编译器.

你必须在/ usr/local/include中创建目录,然后在位内创建一个头文件stdc ++.h并将这个gist的内容粘贴到其中.然后,它应该按预期编译.


因为,/ usr目录在Mac OSX上默认隐藏.

  1. 打开Finder.
  2. 单击菜单栏上的Go,然后单击Go to folder或直接按Command + Shift + G.
  3. 输入路径/ usr/local/include
  4. 现在按上述步骤进行操作.

  • 使用上述路径,不适合我。但通过这条路径,它正在工作“/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/” (2认同)