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

106 comments to 0.9 — Configuring your compiler: Build configurations

  • jamesL

    Hello :) I have a question about compilation in Code Blocks. So you say that in Visual Studio the Release version of the hello world exe was 12KB. But, when I compile this program in Code Blocks the Release version is 542KB! And the Debug version is 1MB. Why is this?

    • Alex

      I'm guessing you're compiling in the C++ runtimes statically (so your executable has its own copy), whereas Visual Studio is compiling them in dynamically (where one copy is shared amongst all applications).

      • jamesL

        Hm, interesting. By "shared among all applications" do you mean the runtime is hosted by the OS instead of in the application itself? I could see this causing problems on systems where the runtime you compiled for isn't available (though that shouldn't really happen that often I guess), like say you build a program for C++ 14 and the computer only has C++ 11 support, that might cause issues if you try to use c++ 14 stuff which you are likely to do. I guess there are pros and cons to each way, the main pro for dynamic compilation being small app sizes which can be good sometimes :) Speaking of, what is the performance like between statically vs dynamically compiled Code? Do you ever go over that in these tutorials?

        • Alex

          Yes, in the case of dynamic libraries, the runtimes are hosted by the OS and applications can dynamically link to them. This generally means you can't just distribute your program as a standalone executable -- it now needs to have an installer and distribute the runtimes, to ensure they're installed on the system.

          There's slightly more overhead in calling a dynamically linked function than a static one, but on modern architectures this is fairly negligible. In some cases, statically linked might be more performant, in other cases dynamically linked might be. It's hard to say without knowing the particulars of your program, and it's probably not substantive anyway.

  • My dear c++ Teacher,
    Please let me a comment regarding Code::Blocks configuration. You state:
    "In Code::Blocks, you should see a toolbar item called “Build Target”:"
    I do not see such toolbar, but one called just “Build”. In the drop-down menu last tool is “Select target”. Clicking on it a small menu appears at its side with two options. One (checked) “Debug”, and other “Release”.
    With regards and friendship.

    • Mateja

      I apologize for correcting you, but when you hoover with your pointer over the drop menu you've mention (in CodeBlocks), it will pop up a message saying "Build Target".


      • Mr. Mateja,
        Please accept my thanks for your message and my sorry for delay in response. Version 16.01 of code::blocks (you can download it in less than 1 minute) has “Select target” instead of "Build Target". That's all the difference. But for a begginer (as me) it is problem.
        With regards and friendship.

  • Jamiu

    Pls I need your help on my c++school assignment how would like contact you? Pls I will prefer talking with
    Thanks in advance

  • Jamiu

    May Allah bless you for the great work u are doing

  • Aparna

    Thanks Alex for such a wonderful tutorial :) Each topic is very much exciting.

  • Trebor

    My first question as a newby. Where is the executable? I had a look at the project folder "HelloWorld" and didn't find any .exe file after the compilation. Thanks!

    • Alex

      It depends on your compiler.

      Visual studio normally puts them under // (e.g. C:\Users\myname\Documents\Visual Studio 2015\Projects\ConsoleApplication1\Release)

  • Kunal

    M learning it from your site. THANKS A LOT bro !

  • what is difference between hacking and coding

  • Methos

    I'm using Code Blocks and my Build Target dropdown only contains the term 'default'. Is there something else I need to install to get the debugger/release options?

    It's not tremendously important, but I had been using Dev-C++ on this project and switched to Code Blocks, for a variety of reasons, one of which was that when I tried to tone back the debugging (I was curious how much of a difference in size it was making), the compiling process would hang. So I'm mildly curious if there's a reason that would happen.

    It's been compiling and running fine in this default mode.

    • Alex

      I'm not very code::blocks proficient, so I'm not sure why this is happening. Normally build targets are set up during project creation. When you create a new project, is it giving you the option to create a debug and release build target? Also, you might check to see whether you're running the latest version of code::blocks.

      • Methos

        Okay, setting it up during creation might be the issue. The project I'm working on originally was in Dev-C++, so I didn't set up much of anything besides importing it. CodeBlocks has been doing some other funny things like forgetting files that are part of the project if I don't do a complete recompile every time (specific to files I wrote after switching IDEs). I'll try starting something from scratch and see if that's clarifying.

        I don't know that it's the newest version as of today, but I made the switch around three months ago, so this isn't like Dev which was whatever version shipped on this computer a decade ago.

  • J

    I'm using my Mac and am running Xcode. I can't seem to find how to switch it between debug and release.

  • sajjadhussain

    I have two queries.1)I don't understand builder configuration?Secondly, is project  a space where it stores .cpp files and how will it decide  to compile or link files?

  • Alan

    This website is the best thing ever created. It does not get the fame it deserves.

  • Devin

    uhm.. it keeps looking me back to .6a on the tutorial...

  • Ar

    Hello Alex,

    Even after installing code block mingw it says compiler not found so reinstalled twice still same error for every install.Please help me asap.

    learncpp fan

  • jojo

    how we can know about executable of program?

  • apoorvaa

    hi Alex,
    I have been following your tutorial and i am a begineer who didn't have any prior knowledge of programming. I started with it - that is installed code blocks and wrote my first program but when i build it following error was given-

    ["a - Debug" uses an invalid compiler. Probably the toolchain path within the compiler options is not setup correctly?! Skipping...
    Nothing to be done.]

    also if I debug it prints debug executable is not set.

    please help how to fix it as soon as possible

    • Alex

      Sounds like your Code::Blocks is set up incorrectly. It's not clear to me why. This article may help, but if not, try searching for "Code::Block debug uses an invalid compiler" on Google and see if any of the articles that come up are helpful.

  • This phrase:
    "For example, when the “Hello World” program from the previous lesson was built using Visual Studio 2013, the executable produced in the debug configuration was 65kb, whereas the executable built in the release version was 12kb."
    has made me smile a bit.

    When I was around 12 I've got my first computer, the glorious Commodore 64. Talking about mid-80s. The C64 had a mind-blowing 64 kb of RAM and 20 kb of ROM. The fantastic programmers of that time were able to pack whole arcade games with flashy 320x200 pix graphics and 3-channel music in that tiny memory. And today we need 65 kb to debug a single-liner program which writes "hello World" on the screen... Boy, something must have gone terribly wrong in the meantime. :o

    Sorry for this short rant, keep up the great job!

  • Shakeel

    Thank you ALex! Someone finally made a tutorial that is noob(let's be honest here) friendly. It actually teaches me about all the concepts anf stuff and doesn't act as if I somehow learnt all about coding before-hand. God bless you man, God bless you.

  • ayesha

    I can't install VS ??in window 7 32 bit OS

  • techsavvy....aye

    i use devc++ i have a problem with debugging  i get an error zlb.1not found or somthin like that plz help.

  • liv

    code::blocks v13.14
    In compiler toolbar,the dropdown that seems to be "Build target" item is inactive.
    "Build options" and "Properties..." items from Project menu is inactive.  
    I still can't access ...

  • Fred

    I tried the HelloWorld example, and was surprised by the size of the executable. For the debug build, the .exe file was 943KB, and for the release build it was 467KB. Is this normal? I am using CodeBlocks v12.11


    • Alex

      On Visual Studio 2010 Express, my debug executable was 41kb and my release executable was 8kb.

      By default, Visual Studio uses a dynamically linked C++ runtime .dll, so the C++ runtime isn't included in the size of the executable. However, even when I statically linked the C++ runtime, my release executable was still only 98k or so.

      I suspect the rest is simply optimization. Preliminary investigation seems to indicate that Visual Studio does a better job optimizing than the GCC compiler.

  • liv

    Thank you for this delightful tutorial.
    I've got a problem to find “Build Target” item and its dropdown ( code::blocks 13.12 )

  • Batuhan

    ok i'm in debug because i'm learning :D

  • I have been a command line user since very beginning, and while reading this tutorial, I am trying the code on my linux machine (vi editor, and g++). Is it worth to try out an IDE, Will I miss something which only IDE can provide?

    • Alex

      You won't lose much by running your programs from the command line, but I would say it's significantly harder to debug them from the command line than from an IDE.

      My recommendation is to use an IDE. They exist for a reason (because they make development easier). You can always go back to the command line once you've learned C++ (but you probably won't want to).

  • Francisco

    Thank you very much for this wonderful tutorial.
    May God eternally bless you.

    Dom. Rep.

  • Makeral

    Thank you so much for this entire tutorial. I just begun reading through (far from finished) and it really guides us to the key points and key words for coding.

  • Loganathan

    Thanks much Alex for your efforts and generosity of sharing the knowledge.The entire tutorial is very well constructed with the basics and the much needed logical reasoning. I am very much surprised with your continuous efforts to add the contents.I am sure whoever visiting this site would expand their programming skills.

    • John Longa

      I wholeheartedly assent to your analysis and concur with your conclusion.  Thus far, the in-depth knowledge presented here has far exceeded my expectations.

      . . .   ; )

Leave a Comment

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