4

I am new to C++ on Mac OS X, and I need to know how to get some details:

  1. How can I get the default compiler for C++ and C?
  2. How can I change the default compiler?
  3. How can I set the compiler in a CMakeLists.txt file when using CMake?

2 Answers 2

2

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 a dialogue box saying you to download and install GCC and its respective command-line tools. This method is preferred, because installing Xcode from the App Store will take you time and as well as consumes your data (4.7 GB).

Since you need only GCC, this is better because it even saves you disk space by installing you only GCC files.

2

I don't think Macs come with a C/C++ compiler by default anymore. I recommend that you install Xcode and Xcode command line 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. In other words, 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:

How do I use a different compiler?

1
  • This now gives you clang the llvm C compiler and not gcc
    – mmmmmm
    Commented Nov 8, 2022 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .