File Not Found Error while including bits/stdc++.h

The file is distributed with GCC. You install GCC with Macports or Homebrew.

brew install gcc


Since, bits/stdc++ is a GNU GCC extension, whereas OSX uses the clang compiler.

You have to create bits directory inside /usr/local/include and then make a header file stdc++.h inside bits and paste the contents of this code inside it. Then, it should compile as expected.


Here are the steps that I followed, if someone is still looking for an answer.

  • brew install gcc
  • gcc --version
  • cd to InstalledDir path:
    1. cd /Library/Developer/CommandLineTools/usr/bin
    2. cd ../include
  • create bits directory in there. use sudo if permission issues
    1. sudo mkdir bits
  • copy stdc++.h link in bits directory, in my case I downloaded it in Downloads.
    1. cd bits
    2. sudo cp ~/Downloads/stdc++.h stdc++.h

This was enough for the compiling.


Did this

{
"cmd": ["/usr/local/Cellar/gcc/6.1.0/bin/g++-6", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c",

"variants":
[
    {
        "name": "Run",
        "cmd": ["bash", "-c", "/usr/local/Cellar/gcc/6.1.0/bin/g++-6 '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
    }
]
} 

after doing brew install gcc and it's working. The g++-6 is the version of the compiler that gets installed, it may be different for different users. Thank you!