LoginSignup
5
1

More than 1 year has passed since last update.

'bits/stdc++.h' file not foundの対処法

Last updated at Posted at 2022-02-26
#include <bits/stdc++.h>
using namespace std;

int main()
{
	cout << "Hello, bits!" << endl;
	return 0;
}

上記コードをコンパイルすると以下のエラーが発生しました。

$ clang++ test.cpp
test.cpp:1:10: fatal error: 'bits/stdc++.h' file not found
#include <bits/stdc++.h>
         ^~~~~~~~~~~~~~~
1 error generated.

bits/stdc++.hファイルが存在していないというエラーが出ています。

以下解決策です。

1. clang -v でデフォルトで参照するパスを確認する

$ clang++ -v test.cpp 
Homebrew clang version 13.0.1
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
... 省略 ...
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/opt/llvm/bin/../include/c++/v1
 /usr/local/Cellar/llvm/13.0.1/lib/clang/13.0.1/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks (framework directory)
... 省略 ...

#include <...> search starts here: 以下に参照しているディレクトリが表示されています。

2. パスにbits/stdc++.hを作成する

1.で確認したパス内にbits/stdc++.hを作成します。

https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/precompiled/stdc%2B%2B.h
こちらからソースをコピーして貼り付けます。

$ cd /usr/local/opt/llvm/bin/../include/c++/v1
$ mkdir bits
$ touch bits/stdc++.h # ここにソースを貼る

めでたくこれで動きました。

$ clang++ test.cpp
$ ./a.out
$ Hello, bits!

参考

gcc コンパイルオプション備忘録

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1