Change eclipse's default launch configuration for all C/C++ projects - c++

Although there might be questions on SO that appear similar to this one I assure you that none of those have been able to answer mine.
I've been figuring out a way to sort of "automate" (I guess you could say) my eclipse projects. To elaborate, let's say I create a C++ project in eclipse using the project creation dialog. This creates two (default) build configurations for the project (Debug and Release).
The annoyance I have run into is that when launching the project, every time I want to switch build configurations (i.e. Debug or Release) I have to manually change the path to the respective ".exe" in the project's launch config, which is rather cumbersome. (See image below...)
by replacing the "C/C++ Application" field with the following:
${config_name:${project_name}}/${project_name}.exe
The appropriate .exe is launched based on the currently active configuration. This is exactly what I was looking for.
Currently, however, I have to set the launch config this way for every C/C++ project I make since eclipse only generates a run configuration as seen in the image (which is not what I want). My question is, how can I make eclipse automatically produce this launch configuration for every C/C++ project I make?

Related

Exclude files from Eclipse Indexing that are included in the build

This question provides good answers to the question of excluding files from indexing that are also excluded from a build. An open question remains: how does one prevent files that are part of the build from populating the code-completion or code-insight functions?
My use-case is a TrueSTUDIO (was System Workbench, was bare Eclipse) project which includes some modules from another project. They are wrapped in safe-to-use stubs and wrappers and should never be called directly. The external modules cannot be edited because they must stay in sync with the other project, so their filenames and other symbols clash confusingly with the current project's. When using code completion to include a header or complete a function name, the filenames and function names of the modules that are not to be used directly appear in the completion lists.
I wish to continue to include the modules in my builds, but not have any of their contents appear in the code-complete/insight features.
I see in Project Properties -> C/C++ General -> Indexer there are options to configure the indexer to use a different build configuration. This is promising, but will probably quickly lead to a indexer that is sorely out of sync with the primary build configuration.
Any advice on a practical method?
The only way I found to exclude files from Eclipse indexing is using the abovementioned Indexer-specific build configuration. In my case, it helped with the annoying problem of indexer freezing on .cu (NVidia CUDA) files.
This is how it works:
Prepare a new (Indexer-specific) build configuration.
Exclude unwanted source files from this configuration using the
Source Location exclude filter.
Let Indexer use this particular build configuration.
Eclipse configuration is a bit tricky with Indexer, so this is a step-by-step guide (as for Eclipse 2021-09):
Preparing a new build configuration:
Project->Build Configurations->Manage->New:
Give it a name, e.g., "4indexer".
Select "Copy settings from" with your preferred configuration. In my case, "Debug" worked just fine.
Excluding unwanted source files:
Project->Properties->Paths and Symbols->Source Location:
Select "4indexer" as the configuration to be managed on the top of the properties window.
Apply an exclusion pattern of your choice. In my case, I added "*.cu" at the end of the "Source Folder Exclusion Patterns" list by clicking Add... button and typing *.cu in the "Add Exclusion Pattern" text field.
Reconfiguring Indexer:
Window->Preferences->C/C++->Indexer:
Allow any Indexer to work with a project-specific build configuration (it was tricky to figure it out): check the "Use the build configuration specified in the project's indexer settings" radio button.
Project->Properties->C/C++ General->Indexer:
Check the "Enable project specific settings".
Select the new build configuration for your project Indexer: check the "Use a fixed build configuration" and select "4indexer" from the drop-down list below.
I also unchecked the "Index source files not included in the build", but I'm not sure if it is necessary.
Sometimes Indexer is trying to reindex a project as you try to reconfigure it, freezing Eclipse. So, I turned it on and off and restarted Eclipse a few times.

Eclipse C++ Setup, Path to executable not set

I try to program some stuff in c++ with eclipse, but I have slight difficulties.
When I create a new Project compiling and making works fine but when I try to run the Application I get the following error message:
"Launch failed. Binary not found"
So what I found out by using google is this workaround:
-right-click on the projekt in the projekt explorer
-select "run as" and then "run configurations"
-expand "c/c++ application" in the navbar on the left
-and in the main tab of the project select "browse"
-navigate to folder "debug" and select the .exe
after I do that, running works fine but I have to do it again every time I create a new Project, is there a way to automate this process?
And what I also noticed: I don't have a "binaries" folder in my projects in the project explorer, maybe its related to that, but I really don't know.
Any help is appreciated
Thanks
Tim
Edit: added a video: http://youtu.be/RKnTOkoHFRU
There will only be a Binaries folder if the build was successful. You will have to manually build to get a binary in order for the Binaries folder to appear. Likewise, if you clean (remove) your build folder then Binaries will disappear.
I would guess that Eclipse cannot find your binary "out-of-the-box" because you are using external tools to manage the build process; that is, if you have a custom makefile project (or another type of project that uses another tool to handle the building) then Eclipse will not be able to provide a default run configuration because it does not "know" where the binary is or even which binary to run if there are multiple. Thus, you have to set up the Run Configuration as you are doing now.
If you create a project and let Eclipse do the building, then Eclipse can find the binaries automatically. For example, simply create an "Empty C++ Project" under "Executable". Write some hello world code. Click build. Then click run. Eclipse launches the binary because it is managing the build process and thus "knows about" where the binary ends up.
Open project properties (Right click on your project, choose Properties on the menu)
C/C++ Build -> Settings
Click on Binary Parsers tab and check PE Windows Parser
as seen here stackoverflow.com/questions/9407430, answer number 3 or 4
In my case
I just save the programme. Press CTRL+B to build it.
Refresh it.
Then run the programme.
Now you can see this will work fine.
I have already answered this for other question see the link Launch Failed Binary not found Eclipse for C in Windows at 10th number.

The program file specified in the launch configuration does not exist

I am facing some problems regarding eclipse for c/c++. I am trying to create a new project, I provide the code, and after running the code I get this error:
The program file specified in the launch configuration does not exist
C:\Users\elisabeth\workspace\mm\Debug\mm.exe not found
Please notice that I am working with spice toolkit; I set the path for the "include" files and the libraries, but still I can not have a result.
What causes this error and how can I resolve it?
Right click on your project --> Properties
Run/Debug settings
Delete whatever is set as "launch configuration for '........'
Project --> Clean
Project --> Build Project
You can create a run configuration. Go to Run > Run Configurations. Click New button, fill C/C++ Application field, i.e., insert path to your executable. The new configuration will appear in the list which appears when you click to the arrow next to run button.
Of course this assumes your can build without problems, otherwise you won't see an executable to point to.
You can clean the project, build it again and run it as a local C/C++ application. Simplified steps as follows,
Right click on the project
Clean Project
Again Right click on the project
Build Project
Again Right click on the project
Run As ->
Local C/C++ Application
As the error reads:
C:\Users\elisabeth\workspace\mm\Debug\mm.exe not found
First of all you need to check whether there is an executable "mm.exe" in your Debug folder. (Of course, it is not there and that is why the error)
Go to Project > Clean
and you should see some files being deleted from your Debug folder
Go to Project > Build Project
and you should see some new files being generated e.g. mm.d, mm.o, mm. This "mm" is probably the executable you're looking for
Now that you know what your executable is, you should tell eclipse what file to execute instead of mm.exe. Go to Project properties and in run debug settings create a new configuration (or edit an existing configuration, if there is one already). In this configuration, in main tab, in C/C++ Application specify a full path to "mm". Which, in your case is - "C:\Users\elisabeth\workspace\mm\Debug\mm"
A better way to do this in eclipse is:
${project_loc}/"your folder"/"your executable file"
e.g.${project_loc}/Debug/mm
what worked for me is file->refresh
then do the Debug configuration again by choosing the right c/c++ binary again.
Avoid troubles with configuration by going into Project properties > C/C++ build > Refresh Policy and specify your project folder. The configuration option "Search project" will show a correct folder then and you will see whatever you build there - Debug, Release or both. You don't want to specify the folder using Browse option every time you import project or switch configurations.
As this is the first SO discussion that appears for this topic on Google and none of the answers solved the problem my students were having, I would like to mention the solution we eventually found from this answer:
Open project properties (Right click on your project, choose Properties on the menu)
C/C++ Build -> Settings
Click on Binary Parsers tab and check PE Windows Parser
Keep clicking Move Up until it is at the top
This had been set to Elf, even though we were using a freshly downloaded Windows version of Eclipse.
sometime missed closing curly brace can be part of a problem. Make sure prototype your function at the beginning of the file. Then right click your project in the left side bar. click clean project. then click build project and finally run project
I encountered similar issues and their related problems a few days ago. Finally, I found out that, just because I had moved my project folder (workspace folder of Eclipse) to another place so Eclipse could not find what its need as usual.
Solution: I just set the workspace to my new place (Hey Eclipse, my workspace now is here) :
Menu "File" -> "Switch workspace" -> "Other..." -> click "Browse..." button and point to new place then click "Select Folder" button and click "Launch" button.
Nice day.

Visual studio 2010 - retain project properties between different build configurations?

I have two projects in my solution. I am currently using the default configuration mode which is 'Debug'. When I want to do a 'Release' build, I switch to Release-mode and then I see all my previous projects properties are set to default, meaning I have to add all properties again manually to this mode.
Is there a convenient way to solve this in VS2010, for example to copy all properties like include paths, preprocessor macros, build macros, etc from 'Debug' to 'Release' mode?
Configuration settings are stored in .vcproj / .vcxproj file. You could open it in some text editor and copy some settings manually, but it wouldn't be convenient. For now you could just open projects properties and copy these settings while switching Debug / Release configuration in the upper left corner of that window.
Next time when you are setting properties that are intended to be the same for all configurations, choose Configuration: All Configurations to avoid troubles.
Property sheets can solve this and a few other property-related issues with ease.
In short, all the properties in a project are just nodes in an XML document, and the property group nodes can have a condition attribute. They're easy to change in any text editor, but a lesser-known feature is the ability to import other XML documents, which can provide settings (for all but a few project-specific ones).
This blog post has a good tutorial on using project sheets, and some more info in this question. You can create them in Visual Studio, edit them (including copying your existing project settings over), then attach them to your project with the property manager (not the property window).
The groups in your property sheet use the same syntax as regular settings, and can be set for all configurations or filtered to only apply on some. They can also be filtered by project name and a few other things, using VS' variable and condition system. For example, I use:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization>
<EnablePREfast>true</EnablePREfast>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
</ItemDefinitionGroup>
for some of my builds, to apply the same settings to all project (full file here).
One of the most convenient uses is giving the build directory in the file, so all your projects build uniformly into the same directory (make sure to use the project name for the output).
Managing almost all the properties across multiple different builds (debug, release, win32, x64 etc.) can be accomplished with a single collection of settings by using Macros.
Thus, before editing a project settings, make sure you've set Configurations to All Configurations and, Platform: to All Platforms. Now almost all settings can be done in this way, across all the different configurations. Say, you want different configurations and platforms to use different versions of various libraries. Assuming you are using a naming convention that's consistent across all projects, you can then use:
Additional Library Directories: ..\..\foo\bar\lib\$(Platform)_$(Configuration)
You can see what macros will expand to, by hitting the edit button, and then clicking on the Macros>> button.
You could also recreate the new mode you want using the configuration manager and then you can choose from which configuration you want to copy all the settings.

Makefile-based Eclipse CDT with run/debug launch configuration depend on release/debug build configuration

I have a Makefile that based on given target (all/debug) generates executable in release/debug directories on the project folder.
I have setup the Eclipse-CDT C/C++ build behavior mechanism to generate the right output depending on the active build configuration.
For example the "release" build configuration will call "make" with "all" as the behavior, that makes release/output file, "debug" configuration makes a debug version at debug/output
So far so good, but when I need to setup the "run configurations" I should enter the path for the binary (search project just does not show anything), Variable ${ConfigName} also does not expand there so I cannot use something like ${ConfigName}/output as binary to run/debug.
I also tried adding release and debug to the "Paths and symbols"/"Output location" and that not help either.
I can enter the relative/absolute path (for examle ./release/output) there and if I hit run, it runs the binary or if I hit debug it debugs it. However, because of the reliance on the path I have to have two launch configurations one for debug and one for release.
The problem is that run and debug configurations are basically the same only one has the option to customize gdb, which makes it very confusing. Regardless of whether it is debug or release active, one can run/debug any of the four combinations!
Is there anyway I can run/debug what actually is built? so if the debug build is active one can run/debug the debug build? I am not even constraining the debug build to be non-runnable or the release build to be non-debuggable, I guess that is asking too much. The problem is because of the two launch configurations, and I cannot find anyway to make it just one that depends on the build configuration.