GCC vs CLANG: how to include bits/stdc++.h
For compiling c++, there are many compilers in the market, but 3 of them are very popular.
- Visual C++
- GNU Compiler Collection (GCC)
- Clang
Among them, Visual C++ was developed by Microsoft, and they don’t support other platforms like Linux. (Typical Microsoft 😛).
GNU was a project, started by Richard Stallman in 1984, which eventually produced many popular open-source software tools like Make, Sed, Emacs. GCC was one of them. GCC was used by all UNIX based OS. Apple also used it for macOS. But over time, Apple wanted to add many features to C++ for their own requirements which weren’t accepted well by GNU developers. So Apple engineers made a separate branch for their own version of c++ compiler, which is eventually called CLANG.
And that’s why some features we get GCC but not in CLANG. Most competitive programmers, use include<bits/stdc++.h
to include all possible header files that might be needed for writing that program. But if we are using macOS, it can’t recognise include<bits/stdc++.h
.
To solve this problem,
- open finder then click
Go to folder
- paste this address
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/
- Create a new folder name
bits
- inside
bits
create a new file namedstdc++.h
. To create a file open terminal and inside that folder and typetouch stdc++.h
- paste the code written below inside that file.
/** @file stdc++.h
* This is an implementation file for a precompiled header.
*/
using namespace std;
// 17.4.1.2 Headers
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
save and exit. After that it will work fine.
originally published in https://saadnoor.com/gcc-vs-clang-how-to-include-bitsstdc-in-mac/
Top comments (1)
I did everything according to this, but it says "fatal error: 'bits/stdc++.h' file not found". Do you notice anything wrong with my c_cpp_properties.json?