G++ on MacOS
How to access <bits/stdc++.h> and <ext/pb_ds> easily
The problem
MacOS have a special compiler for C/C++ which is clang, you would like to use G++.
The problem is when you run:
g++ --version
You will see it’s Clang.
Fixing
You need to put a g++
program in a path earlier than /usr/bin
, you can check it by:
echo $PATH
Usually /usr/local/bin
should be earlier than /usr/bin
, so you can copy g++-14
from homebrew to it like this:
brew install gcc
mkdir /usr/local/bin
sudo ln -s /opt/homebrew/bin/g++-14 /usr/local/bin/g++