GCC vs. Clang and How to use bits/stdc++ header in MacOS

GCC vs. Clang and How to use bits/stdc++ header in MacOS
Photo by Mitchell Luo / Unsplash

For compiling c++, there are many compilers in the market, but 3 are very popular.

  1. Visual C++
  2. GNU Compiler Collection (GCC)
  3. 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, and 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++ the compiler, which was eventually called CLANG.

And that’s why some features we get in GCC but not in CLANG. Most competitive programmers 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,

  1. open finder then click Go to folder

2. paste this address /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/

3. Create a new folder name bits

4. inside bits create a new file named stdc++.h. To create a file open terminal and inside that folder and type touch stdc++.h

5. 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.