Faced this issue with Mac M1 chip and was unable to compile and run a .cpp file which had #include <bits/stdc++.h>
header.
Upon investigation I got to know that the <bits/stdc++.h>
header is not part of the C++ standard; rather, it's a header file specific to the GNU Compiler Collection (GCC). Apple Clang, being a different compiler, may not include this header by default.
- So, specific to your project configurations, you can set the
compilerPath
to point at the path where you have installed the GNU g++ compiler
.
- To find out if you have ever installed GNU gcc compiler with homebrew before, use the command
brew info gcc
. This will give out the version of the compiler if it exists with homebrew list.
- Use the command
which g++-{your-specific-version}
eg. which g++-13
, in my case this gave the output of /opt/homebrew/bin/g++-13
which I then used to set the compilerPath in C/C++ Configuration file as well as the tasks.json
file attached below.
//for c++17 build
{
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "/opt/homebrew/bin/g++-13",
"args": [
"-std=c++17",
"-o",
"${fileBasenameNoExtension}",
"${file}"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "compile and run",
"type": "shell",
"command": "/opt/homebrew/bin/g++-13 -std=c++17 -o ${fileBasenameNoExtension} ${file} && ./${fileBasenameNoExtension} < input.txt > output.txt",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
xcode-select --install
and then restarting vscode solved the problem for me.g++
installed.