How to get the default compiler of c++ on Mac os x

I am new in c++ on Mac os x and I need to know how to get some details:

  1. How to get the default compiler c++/c?
  2. How to change the default compiler?
  3. How to set the compiler in a CMakelists.txt file when using CMake?

Solution 1:

You can just open terminal and type in gcc. If gcc is already installed on your mac then it will show as no input files. If you don't have gcc installed then you will get dialogue box saying you to download and install gcc and its respective command line tools. This method is prefered because install Xcode form the App Store take you time and as well as consumes your data (4.7GB). Since you need only gcc this is better because it even saves you disk space by installing you only gcc files. I hope this helps :-)

Solution 2:

I don't think Mac come with a C/C++ compiler by default anymore. I recommend that you install XCode and XCode commandline tools from the App Store. That will give you the gcc compiler (and probably LLVM as well).

Without knowing your build process, I can't tell you how to set a default compiler. There will be an option in XCode as well as options with command-line build tools. IOW, Macs do not have a system-wide default compiler setting that I'm aware of.

Here's the official documentation on how to use a different compiler with CMake. https://gitlab.kitware.com/cmake/community/wikis/FAQ#how-do-i-use-a-different-compiler