Search

0.6a — 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 directory the executable will be output in, what directories the IDE will look in for other code and header files, whether to keep or exclude debugging information, and how highly to have the compiler optimize your program. Generally, you will want to leave the settings at their default values unless you have a specific reason to change something.

When you create a new project in your IDE, the IDE will generally 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 developing 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.

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.

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.

Switching between debug and release in Visual Studio

There are multiple ways to switch between debug and release in Visual Studio. The easiest way is to find the “Solution Configurations” dropdown in the Standard Toolbar Options menu:

VS Solution Configurations Dropdown

It should be set to Debug or Release. You can change which one you’re using by selecting it in the dropdown.

You can also access the configuration manager dialog, by selecting Build->Configuration Manager, and change the “Active solution configuration”.

Switching between debug and release in Code::Blocks

In Code::Blocks, you should see a toolbar item called “Build Target”:

VS Solution Configurations Dropdown

It can be set to debug or release in the dropdown.

Summary

The build configuration holds the settings for different versions of your project. You generally won’t need to touch these settings, but you may want to switch between debug and release.

Rule: Use the debug configuration when developing your programs. When you’re ready to release your executable to others, build it using the release configuration.

0.7 -- A few common C++ problems
Index
0.6 -- Compiling your first program

46 comments to 0.6a — Build configurations

  • 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.

      . . .   ; )

  • 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.

  • Francisco

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

    Dom. Rep.

  • 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).

  • Batuhan

    ok i’m in debug because i’m learning 😀

  • liv

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

  • 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

    Thanks

    • 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

    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 …

  • techsavvy....aye

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

  • ayesha

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

  • 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.

  • 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 320×200 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. 😮

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

  • 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
    thx

    • 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.

  • jojo

    hey!!!
    how we can know about executable of program?

  • 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.

    thanks
    learncpp fan

  • Devin

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

  • Alan

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

  • 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?

  • J

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

  • 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.

  • what is difference between hacking and coding

  • Kunal

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

  • 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)

  • Aparna

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

  • Jamiu

    May Allah bless you for the great work u are doing

  • Jamiu

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

Leave a Comment

Put C++ code inside [code][/code] tags to use the syntax highlighter