Search code examples
c++xcodemacosg++clion

when I use g++ on the command line, the clang++ compiler is used on the Mac OS


I know that gnu gcc compiler is preinstalled on Mac OS. But for some reason CLion does not see it. And moreover, when compiling in the console, clang++ was hung up on the g++ command. How to fix it so that CLion sees it and compiles through it, and so that gnu gcc is used in the console

I deleted XCode and CLion couldn't find anything at all, and XCode takes up a lot of space and I don't use it. I want to use GNU gcc on my Mac


Solution

  • gcc is not pre-installed on macOS. gcc --version would show that it's actually clang. In fact, no C or C++ compiler is pre-installed, if we want to be technically correct.

    Uninstalling XCode uninstalled your compiler as well. That shouldn't be a surprise, as installing XCode is probablly how you got the compiler in the first place. If you just want the command line tools, you can xcode-select --install them. That command may require sudo privileges.

    You will still not have gcc at this point, just an alias that points to clang. You would then follow the instructions to install homebrew and install gcc via the brew command. Once the installation finishes, you will be given instructions. You need to follow them, otherwise you'll still be using the aliased clang.

    Or you could just use what's provided by default, as my guess is that you're not going to be writing anything that actually requires gcc.