Skip to content

Instantly share code, notes, and snippets.

@hugoledoux
Last active September 9, 2020 08:44
Show Gist options
  • Save hugoledoux/2e91ed3efbfa8ca5da1ea27e522d2b34 to your computer and use it in GitHub Desktop.
Save hugoledoux/2e91ed3efbfa8ca5da1ea27e522d2b34 to your computer and use it in GitHub Desktop.
how to install C++ compiler

NOTE: There are usually many options to set up a development environment on each operating system. What proposed here is not the only option, but I try to minimize your effort. Besides, you may skip some of the steps if they have been properly set up already. Or if you know what you're doing, you're allowed to use any C++ you want. As long as you know how to deal with a CMake project, it's good.

Here's a small test project with one C++ unit (hello.cpp) and a CMake file (the project file to tell the compiler how to compile the project).

Windows

Install Microsoft Visual Studio Community 2019, and not Visual Studio Code. This comes with the IDE and the C++ compiler.

Then install CMake: direct link to Windows 64bits installer.

macOS

Install the compiler, in the console type: xcode-select --install Instead, you could just install XCode, but it's way bigger and XCode itself is not necessary; if you already have XCode installed then you're good no need to do anything.

For the IDE, install CLion. It's free for 30days, and as a student you can request a free licence.

CLion allows you to open automatically a CMake project, so just open the folder where you unzip the small project and voilà you're up and running.

Linux

Install C/C++ compiler and related tools through a few commands

  • If you are using Fedora, Red Hat, CentOS, or Scientific Linux, etc., use the following yum command:

    yum groupinstall 'Development Tools'

  • If you are using Debian, Ubuntu, and their variants, run the following apt-get commands one by one:

    sudo apt-get update

    sudo apt-get install build-essential manpages-dev

For the IDE, install CLion. It's free for 30days, and as a student you can request a free licence.

Step 2. Build the executable

Just try to compile this simple hello-world project, which uses CMake.

Choose ONE of the following (or whatever you are familiar with):

  • Option 1: Use CLion that can directly handle CMakeLists files to open the CMakeLists.txt in the root directory of the software. Then you should have obtained a usable project and just build. I recommend using CLion

  • Option 2: Use CMake to generate project files for your IDE. Then load the project to your IDE and build.

  • Option 3: Use CMake to generate Makefiles and then make (on Linux/macOS) or nmake(on Windows with Microsoft Visual Studio).

For more details, see How to Build a CMake-Based Project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment