0.9 — Configuring your compiler: Build configurations

A build configuration (also called a build target) is a collection of project settings that determines how your IDE will build your project. The build configuration typically includes things like what the executable will be named, what directories the IDE will look in for other code and library files, whether to keep or strip out debugging information, how much to have the compiler optimize your program, etc… Generally, you will want to leave these settings at their default values unless you have a specific reason to change something.

When you create a new project in your IDE, most IDEs will set up two different build configurations for you: a release configuration, and a debug configuration.

The debug configuration is designed to help you debug your program, and is generally the one you will use when writing your programs. This configuration turns off all optimizations, and includes debugging information, which makes your programs larger and slower, but much easier to debug. The debug configuration is usually selected as the active configuration by default. We’ll talk more about debugging techniques in a later lesson.

The release configuration is designed to be used when releasing your program to the public. This version is typically optimized for size and performance, and doesn’t contain the extra debugging information. Because the release configuration includes all optimizations, this mode is also useful for testing the performance of your code (which we’ll show you how to do later in the tutorial series).

When the Hello World program (from lesson 0.7 -- Compiling your first program) was built using Visual Studio, the executable produced in the debug configuration was 65kb, whereas the executable built in the release version was 12kb. The difference is largely due to the extra debugging information kept in the debug build.

Although you can create your own custom build configurations, you’ll rarely have a reason to unless you want to compare two builds made using different compiler settings.

Best practice

Use the debug build configuration when developing your programs. When you’re ready to release your executable to others, or want to test performance, use the release build configuration.

Switching between build configurations

For Visual Studio users

There are multiple ways to switch between debug and release in Visual Studio. The easiest way is to set your selection directly from the Solution Configurations dropdown in the Standard Toolbar Options:

VS Solution Configurations Dropdown

Set it to Debug for now.

You can also access the configuration manager dialog by selecting Build menu > Configuration Manager, and change the active solution configuration.

For Code::Blocks users

In Code::Blocks, you should see an item called Build Target in the Compiler toolbar:

Code::Blocks Build Target Dropdown

Set it to Debug for now.

0.10 -- Configuring your compiler: Compiler extensions
0.8 -- A few common C++ problems

80 comments to 0.9 — Configuring your compiler: Build configurations

  • oxygène

    Am I the only one using kdevelop for my first program? It's awesome though, don't forget to install cmake before creating your first project.

    • Teddy

      I started using kdevelop myself to compile some github projects. It has come a long way for sure. The ability to import CMake "project" to create a workspace is very slick. KDE has started porting some apps to Microsoft store so I assume KDevelop will make its way there eventually.

  • Dan Satt

    I'm using the new MSVS 2019 RC, and the default build config is debug x86.  I have the option to switch to x64, but I can't particularly think of why I would.  Any insight?

    • Hi Dan!

      Compiling in x86-64 (x64) allows the compiler to use instructions that are unavailable in IA-32 (x86), potentially speeding up your program.
      64bit allows you to access more memory than you could possibly have, while 32 bit is limited to around 4GB.
      IA-32 support is decreasing, you might find yourself wanting to use a library which is only available in x86-64.

  • Vinyamin

    Why do I not have the Build menu?

  • Mark

    Since you inserted a new lesson prior to this one (0.8—A few common C++ problems), the following sentence in the fifth paragraph needs to reflect that.

    “When the Hello World program from >>the previous lesson<< was built using Visual Studio, …”

    Should be corrected to read:

    “When the Hello World program from >>lesson 0.7<< was built using Visual Studio, …”

  • Ryan

    Hello! I believe I found a typo in the bottom section. Where you said 'In Code::Blocks, you should see aitem called Build Target', I think you meant to say 'an item' instead of 'aitem'.

  • Mark

    I can't find the Build target toolbar, because I am using codeblocks 17.12. Another question that is when and why do you need to use the highlight option? And last question is what are the "match case" and "use regex" options used for?

  • Willie

    Hello Alex.
    Is there a easy to read section where the variables are listed in a table form so the values can be seen and whatever else ....possibly how the variables are written?
    Trying to make it easy.

    • Alex

      I don't think I understand what you mean. Variables aren't mentioned in this lesson, so I'm not sure what problem you are trying to solve for.

  • Prynce

    Thanks so much I was able to write my first c++ program using Dev c++
    "Hello world!" Was displayed on my screen

  • Dear Sir!

    I am revising your lessons after completing the chapter 1 (including its sub-chapters).
    I have downloaded and installed Code Block-version 16.01 (Release 16.01 rev 10702 (2016-01-25 19:50:14) gcc 4.9.2 Windows/unicode - 32 bit).

    I failed to locate any 'Build target' there even after pasting my 'HellowWorld' program which otherwise runs perfectly.

    Can you please guide me in this respect?

    Thank you.

    Best regards.

    • Alex

      Did you set up both a release and debug release configuration when your project was created? Check out the screenshot here: -- it shows where you should be able to see your active build target on the interface (in this screenshot, the Debug configuration is selected)

  • Kushal Singh

    Hello Alex,

    When I navigate to Debug dir of my project folder , I find files with extensions: idb,pdb and pch. what are these files for and when are they generated ?


    • Alex

      .idb and .pdb are debug files produced by Visual Studio. .pch is a precompiled header file. These are all generated when you compile your program in debug configuration with precompiled headers enabled (which they are by default).

  • Kushal Singh

    How can I check the size of executable produced in debug/release configuration ?

    • Alex

      Use your OS file explorer/browser and find where your IDE put the executable for each of your configurations. This is most likely in a subfolder inside your project directory.

  • phong nguyen

    Hi, I just want to say thank you for the continuous efforts over the past couple of years. You rock!!!

  • Ahtazaz Khan

    Hi, i'm new here, i love your effort. i'm doing bachelor in Computer science. I have a little bit programming skills.But now i have a aim to learn Programming from the 0.I found your work best.Amazing tutorials.I have a question about building configurations.I have don't clear the build-configuration.Mean,What is the purpose of Build Configuration.How and when debug and release configurations use...?

    • Alex

      You'll generally use a debug configuration when developing your code or running it for your own purposes. This enables all debugging functionality, making it easier to find errors. If you decide to release your executable to others, you'll build it using a release configuration. This strips out all debugging information and uses more compiler optimizations, making your code smaller and faster.

      You can define custom release configurations as well, but there's no need unless you have special circumstances.

Leave a Comment

Put all code inside code tags: [code]your code here[/code]