How do I set the compiler options? - codeblocks

I am Code::Blocks 13.2 user in Ubuntu 14.04 LTS. How do I set the compiler options, such as compile under Debug or Release mode? I don't see the options readily on the GUI.

'Debug' mode and 'Release' mode are not compiler options. They are options in the
IDE for configuring the whole project (including the compiler options and
all other tool options) between debug mode and release mode.
In the tool bar beneath the top menu bar of the IDE you should see a drop-down menu
that has items Debug and Release for selecting the desired configuration.
See screenshot:-
What the various tool options will be in debug mode and release mode is up to you. The IDE has
sensible defaults. You can set them by navigating YourProject -> Build options
and selecting Debug or Release from the project tree-control of the left
before continuing. See Screenshot:-

To set up the compiler go to Settings->Compiler.
To set up your projects target settings (debug, release, etc...) right click on your project and go to build options.
You may also want to take a look at the over all project settings by also right clicking on the project and going to properties.
If your just editing files on their own you have to add them to a project first (otherwise why are you using an IDE in the first place?) by going to file->new->project

Settings ->Compiler->Global Compiler Settings->and there you can change your settings with flags or defines, and other options.

Related

How to toggle running Xcode project in debug or release mode by using only shortcut keys?

By default, to "run" my project in release mode, I need to edit the scheme's run settings to use "release" instead of debug.
To not have to edit the scheme each time I want to switch between debug and release mode, I created a new scheme which runs in release. But this is still tedious since I need to click on the relevant scheme if I want to switch.
Is there a way that I can automatically (build + run) in debug / release mode using only short cut keys ?
I don't wan't to profile! Because that launches instruments etc.
EDIT: To be clear - I'm always running on the device.
Debugging build: "Product" Menu => "Build For" => "Running" (shift-command-R)
Release build: "Product" Menu => "Build For" => "Profiling" (shift-command-I)
Run without building (whichever you just built): "Product" menu => "Perform Action" => "Run without building" (control-command-R)
The equivalent in XCode that you seek is the "schemes".
Right of the play/stop buttons, there a pretty handy scheme selector. You just need to create a scheme for debug and another for distribution.
In order to make a scheme for debug or distribution, simply go to the scheme configuration (either selecting "edit scheme..." or "new scheme...") and choose the correct build configuration under "Run -> Build Configuration":
Note: I have XCode 9.1, I don't know if this is valid for older versions.
There is one way that I use it for my projects.
In Xcode, go to the the project settings (project, not target) and add "beta" configuration to the list:
Then you need to create new scheme that will run project in "beta" configuration. To create scheme go here:
Name this scheme whatever you want. The you should edit settings for this scheme. To do this, tap here:
Select Archive tab where you can select Build configuration
Then you need to add a key Config with value $(CONFIGURATION) the projects info property list like this:
Then its just the matter what you need in code to do something specific to beta build:
let config = Bundle.main.object(forInfoDictionaryKey: "Config") as! String
if config == "Release" {
// app running in release configuration
}
else if config == "Beta" {
// app running in beta configuration
}
In XCode 7 you can switch between schemes using the shortcut: control-command-right/left bracket (select next scheme, select previous scheme). So I think creating two schemes is your best bet.
BTW, for everyone asking why one would do this - If you are writing a high performance piece of code you will find yourself constantly switching between release and debug mode for a lot of reasons. Release mode (especially in swift with whole module optimization on) takes forever to build and optimization changes stack traces, etc.

XCode 4 - Release Mode Flags, Build Flags, Link Flags

I'm working with XCode 4.6 on MAC OS X 10.8.
I'm new to this IDE and platform.
I have a project I compile and optimizations are turned off by XCode.
It doesn't matter if I set Release Scheme.
I saw at the thread named "Cannot Disable Debugger with XCode 4.5" that it has to do with the flags '-O0' and '-Os'.
I know that some flag set "Debugging Mode" which means no optimization is done and more data is generated by the code to help debugging.
I just can't find the single parameter which controls this behavior in XCode (Like /Mtd in VS).
Which parameter in the XCode options controls this parameter?
Moreover, In VS it is easy to see the build parameters as a command line (Under options, both Linker, and Build).
Where can I see that in XCode?
Thanks.
All the compiler and linker flags can be found within a project's or a target's "Build Settings" (targets can overwrite their projects' settings). To get there, select the project file, then select your current target, and go to "Build Settings". Select "All" and "Levels" at the top to display all available options and where they are set (project or target -- left-most wins).
The options are grouped, e.g., linker options and compiler options, and most of them refer to flags. Xcode shows a descriptive name rather than the full flag name. To see the latter, select the line of interest and select the "Quick Help Inspector" in the right panel ("Utilities" panel). The flag you seem to look for is called "Optimization Level" in Xcode.
You can set each option's value, and Xcode may display some meta information next to the raw value, e.g., "Fastest, Smallest" for -Os, or "None" for -O0. You can set all options for each configuration (by default, Release and Debug) independently. Which configuration is actually used depends on your build action. If you build & run, Debug is used by default. If you archive an application, Release is used by default. However, you can change most of that by editing the schemes.
Update:
To get an idea of the differences between the Release and Debug configuration, look at the "Build Settings" of a given target. If an option's value differs in both configurations (or any other configuration you may have), there's an arrow in front of the option's name which indicates the differing values. E.g., take the "Build Active Architecures Only" setting. In debug mode, it assumes you build for a particular testing device so there's no need to include code generated for other platforms as well. However, if you build your app for distribution, you want to build one app that includes code for all target devices/hardware architectures.
Other options to look into:
-Debug Information Format: The way debug information (crash reports) are stored. In Release mode, this is set to "DWARF with dSym", which means that your crash reports are encrypted so no one else can get meaningful information (symbol names) out of them.
-Strip Debug Symbols During Copy
-Optimization Level, as mentioned above
-Preprocessor Macros: This allows you to make your code (statically) dependent on the build configuration, e.g., to log only in Debug mode
Xcode provides more (and probably more accurate) information on all these options in the above-mentioned "Quick Help Inspector", just select any option.
From my experience, despite the optimisation, Release builds are often faster (i.e., they build faster) and definitely smaller in size.

Can't switch from release to debug configuration in Visual Studio 2010

I downloaded an ASP.NET open source solution and opened it in Visual Studio 2010. VS is running as admin.
Everytime I switch the solution or a project from Active (Release) to Debug and uncheck 'Optimize code' and save, these changes don't stick. The solution or project reverts back to Active (Release).
Why is this happening?
You also have to change it in Configuration-Manager (see pictures).
I just had this exact issue. The solution ended up being:
Go to Tools ⇒ Options ⇒ Make sure "Show All Settings" in the lower left is checked.
Then, in that same window, go to Projects and Solutions ⇒ General ⇒ check "Show advanced build configurations".
I have no idea why this checkbox was suddenly unchecked for me this morning, but this worked.
This is guessing a little, but anyways:
Most likely, you are using build configurations that don't include your start up project for Debug build.
Look for the 'Manage Build Configurations' (I think, no Windows machine nearby) menu item. It will show you a list of projects with tickboxes on the right to show whether it is to be built in the build configuration.
Switch to 'Debug' in that dialog and make sure your startup project - or the project that your starting the build for - is actually included in the build.
PS It is even entirely possible that the 'misbehaving' project is actually lacking a Debug build (it might have a deviant name, like DebugConsole or something else entirely). In that case, use the Project menu to add a build configuration of the proper name for that single project. Afterwards, check (again) that said build configurations are checked in the 'solution wide' build configuration dialog.
HTH
Changing the properties of a configuration doesn't change the current build configuration. If you open project properties, change from Release to Debug and make some changes, after exiting the dialog, you will build on the same platform as before. To change the platform you're building on, there is a combo-box right above the code - use that. You should have all available configurations in the list. When you open the project preferences dialog, the current configuration will be the default one in the dialog.
I opened the csproj file in a text editor. Noticed there were two PropertyGroup sections which look like duplicates, one was Debug|AnyCPU and the second was Release|AnyCPU. I deleted the second one and the debug one showed up.
Luchian Grigore's answer explains correctly one simple misconception that could lead to this problem and aaaaaaa's answer gives another way of correcting it: there is a dialog that looks like you are selecting the configuration to build but you are actually just selecting the configuration to configure.
However neither of their ways of opening the 'Configuration Manager' actually worked for me -- I had to click on the button configuration manager at the top right of the solution Properties.
(Note that the place where you choose the configuration is called Configuration Manager, whereas the place where you manage the configurations is Properties.)

Adding a library to a target

My documentation says
Click on the target and add pgmName.a on General settings of the
target Info.
I don't see a General settings, although I see Architectures, Build Locations, etc under build settings. And there's an info tab and a summary tab, but I don't see a General settings.
Xcode 4 no longer has this tab setup. You'll want to add pgmName.a to the Link Binary With Libraries step under the Build Phases tab of the target. If you're seeing Info and Summary tabs instead of Build Settings, Build Phases, and Build Rules, click on the target rather than the project in the left panel (under TARGETS rather than PROJECT.)

Why does VS force my build to x64?

Before I build, I choose x86 (or Any CPU, too) in the Properties tab for the project.
I save these properties, and if I re-open the Properties tab it's back to x64 as the platform and target, why?
Choosing a build configuration in Properties doesn't actually change the active build configuration. It only allows you to switch between the various build configurations that are defined for your project so that you can edit the settings for each of those configurations. It's only a configuration selector.
The easiest way to change the active build configuration is using the drop-down boxes on the toolbar:
Those commands should be present in your toolbar by default. If you don't see them, follow these steps to get them back where they belong.
Make sure that your .csproj file is not readonly.
Make sure that your changing the build target, not the configuration selector.

Resources