Could someone please help me with an understanding of the Run Configurations in Eclipse?
Here is the issue I am trying to resolve:
I am developing a c++ application using CDT in Eclipse Luna. I have to two source files, let's say I have file_01.cpp and file_02.cpp. Both of them have main() function. Both of these files are in the same project. Essentially I want to compile and then run a configuration #1 and configuration #2 where the gcc compiler would only compile file_01.cpp and file_02.cpp respectfully. I achieved mixed success where under the same configuration I would apply a Resource Configuration filter, but this is inefficient since I have to do/undo same filtering operation many times. I believe this is what the configurations are used for.
I looked at the eclipse manual, found exact place where this topic is discussed. Unfortunately, there is not much info there and also I think that manual might be outdated (some of the menu items are not where manual claims them to be).
So my understanding is that I create a configuration, include whatever files I want to include, compile that configuration and then run that configuration. Question: How do I do that in Eclipse?
Many thanks!!
You can use build configurations for your purpose. You can exclude/include source files from specific build configurations. Run configurations can then be used to run the exe built using a specific build configuration. You can manage build configurations from the project context menu. You can exclude or include files or folders from a build configuration by choosing the potion from the context menu of the file or folder
I want to thank #Sasikanth for the pointer on the Eclipse. His answer helped me to understand how to do it. I just want to go over the process more in detail and explicitly for the benefit of others.
Situation:
let's say you have two files under the same project: file_01.cpp and file_02.cpp.
file_01.cpp has the following line:
int main(void){
cout<<"this is file_01"<<endl;
return 1;
}
file_02.cpp has the following line:
int main(void){
cout<<"this is file_02"<<endl;
return 1;
}
How do we work with two main() functions in the same project. How do we compile files separately and run them separately?
SOLUTION: (I am using eclipse-luna)
1) First, you want to go PROJECT->BUILD CONFIGURATIONS->MANAGE
A new window will open up and you can create some build profiles, lets say PROFILE_1 and PROFILE_2
2) Next, right click on file_01.cpp and choose RESOURCE CONFIGURATIONS->EXCLUDE FROM BUILD. In there choose whichever build profile you want to associate file_01.cpp. In our case: PROFILE_1. Do the same procedure for file_02.cpp
3) Now you are ready to compile each Build Configuration separately. First you need to choose the configuration you want to compile. go to PROJECT->BUILD CONFIGURATIONS->SET ACTIVE and choose the build config you want to compile. Then prese CTRL-B. Do the same thing for other configurations.
4) Now everything is compiled, but you need to tell Eclipse that it needs to run different configs. go to RUN->RUN CONFIGURATIONS. A new window will open up. Under c/c++ application, add a new profile. on the right hand side you will have an combo box choose "Build Configurations" where you can associate RUN config with BUILD config. This will tell the eclipse what to run and when. Once you create your run configs, press OK.
5) in last step, you want to run a specific configuration. For that, you go to toolbar and look for the "play" button. Right next to it, there will be an arrow. You click on it and choose the configuration you want to run.
That is it in detail!! Again big thanks to #Sasikanth for the pointer on how to do it. Feel free to ask questions is any. Thanks!!
Related
I am running a large project in CLion with 10 small projects inside. Each small project has a main function. These small projects should run in sequence, say a->b->c->d->... to ensure the large project run properly.
Currently when I try to debug this large project, I have to manually start the debug session of each small project in sequence, which is annoying.
My question is, is there any convenient way that it can start the debug processes of these small projects for me automatically by one click?
Use "Before Launch" in your Run/Debug configuration to add dependent projects.
From CLion web help:
Before Launch
Specify which tasks must be performed before applying the run/debug configuration. The specified tasks are performed in the order they appear in the list.
Run Another Configuration. Select this option to have another run/debug configuration executed. In the dialog that opens, select the configuration to run.
This option is available only if you have already at least one run/debug configuration in the current project.
Simply put:
In eclipse how do I run a shell/batch script when I build? I have an external tool that can be run by hand but I want to trigger it when the project is built. Using build variables in the script would be an added bonus.
Why I want this:
I work on multi-platform games for mobile. The teams in the company I'm at use X-Code, Visual Studio, and Eclipse (Momentics) for our games. We want to be able to pick up a phone and see overlay on-top of it with information such as who built it, when it was built, what branch and revision it's from, and what library versions are being used. I've done this with X-Code by running a script on build that dumps some of that information to the resource directory of my game that I can then parse at runtime. It's really simple and I'm up for alternate suggestions if you have them; keeping in mind it must work for the three IDE's our developers use.
Bonus Sugar:
In X-Code we can use build variables which would be super nice to have for eclipse as well. I use them to change to the active cocos2d-x repository and get a git log to tell us when the last commit to that repository was made and by who. If that isn't possible in eclipse I can figure something out.
Thanks in advance!
Add a custom builder to your project: open Project properties from the popup menu, on the builders page add a new Program. That will open a "External tool configuration" page.
There you can define a script to run, and also add parameters, where you can add Eclipse variables, such as ${workspace}, etc.
Be careful though: this will run every time when the incremental project builder runs, and the configuration is shared through version control (so beware of absolute paths).
I am new to using IntelliJ. I have only one grievance and that's the compiler. I prefer the way the Eclipse compiler will compile a project and skip classes with errors in them.
This is particularly a problem for if I want to write a unit test for a method I have to fix all errors in the entire project for running a single unit test!
You might say fix your project but I'm working on a project where people have already committed code with errors in it. How can I get around this, I saw there's an option to use the Eclipse compiler in the settings but this has made no difference/I don't know the argument to skip errors.
This fixed it for me on IntelliJ 14:
In Preferences->Build,Exec,Deploy->Compiler->Java Compiler, choose Eclipse compiler. Then check "Proceed on errors", which will appear once you choose the Eclipse compiler.
Then in Run->Edit Configurations expand the Defaults section on the left. Choose the configuration for your unit test framework (eg, JUnit or TestNG).
Then in the "Before launch" section, remove "Make" and add "Make, no error check"
Finally, you may need to delete any existing unit test run configurations so the new launch setting will take effect.
Not sure if this will be effective for what you're attempting to do and how your project is structured, but it worked perfectly well for me in my particular case, in that if your class has a main method, you can right click inside of the actual main method code and select "Run 'classname.main()'" from there.
This worked for me, but obviously may not be identical to your situation.
I got this from another answer located here: Intellij IDEA how to run a class not the entire project?
On IntelliJ 2018.1.4 (Linux): 2018-06-06
In File->Settings->Build,Exec,Deploy->Compiler->Java Compiler, choose Eclipse compiler from drop down. Option "Proceed on errors" should already checked (if not, mark tick on it), which will appear once you choose the Eclipse compiler.
Then in Run->Edit Configurations -> expand the Defaults section on the left. Choose the configuration for your unit test framework (eg, JUnit or TestNG).
Then in the "Before launch: Build,Activate tool window" section(see in end), remove "Build" and add "Build, no error check". Click apply and okay
Finally, you may need to delete any existing unit test run configurations so the new launch setting will take effect. This can be find from Run->Edit Configurations under (eg, JUnit or TestNG). or we can edit it
A clumsy way is to create a new module under your project file and make a test file in src folder of this new module
I'm using Eclipse with C++ code via linked resources on Linux. The code analysis index seems to be corrupted (Goto definition lands the cursor close to, but not on, the definition) Refreshing resources doesn't fix it, neither does restarting Eclipse.
Is there a way to flush the index and rebuild it?
Right-click on your project, go under the Index submenu, and choose either "Rebuild," "Update with modified files," or "Freshen all files."
I don't know the difference between those three options, but one of "Update with modified files" or "Freshen all files" usually fixes it for me.
Also, I'm sure you've already done this, but make sure that you're running the latest version of the Eclipse CDT. Current versions seem to have much more reliable indexing than previous versions.
From http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg10390.html, the differences between "Rebuild," "Update with modified files," or "Freshen all files":
Rebuild: Works for entire projects, only. Clears the index and indexes
the files from scratch. When cancelled it leaves you with an empty or
partial index.
Update with Modified Files: Works on a resource
selection. Checks on individual files whether the timestamp or the
scanner-config has been changed and updates the index for the changed
files.
Freshen All Files: Works on a resource selection. Updates the
selected files in the index. The index is not cleared, it is safe to
cancel the operation.
Go to your project properties -> C++ general -> Indexer.
Do this with 'project specific settings',
(or on 'Configure Workspace Settings...').
Deselect 'Enable Indexer' hit Apply.
Select 'Enable Indexer' hit Apply.
This should completely wipe out and rebuild the index.
Neither of the above worked for me (Eclipse Indigo), index still broken and refusing to rebuild properly. Until applied this one:
http://slsam2.blogspot.com/2012/02/eclipse-cdt-index-not-working.html
The crucial bit of the linked post is this:
Eclipse no longer treats your project as a C++ project. Choose menu File/New/Convert to a C/C++ project. It takes a while to index the source code.
I still wonder how Eclipse can uncontrollably shoot itself in the foot like that. I suspect that installing additional packages can trigger it. Perhaps JavaScript support in my case.
delete only the .pdom file under .metadata.plugins\org.eclipse.cdt.core helps, I got the indexer screwed after upgrading Neon.2 to Neon.3 and this seems to solve the problem.
(this comment already exists above but am not allowed to confirm it up there).
I found that I had the global indexer set to 'Use the build configuration specified in the project's indexer settings',
and the project's indexer set to NOT use project specific indexer settings.
Regardless, it was using the same fixed configuration for the indexer regardless of which configuration I had selected.
The fix:
Window-Preferences, C/C++, Indexer. Select "Use active build configuration" in section "Build configuration for the indexer".
Happy days.
Did you try adding -clean to the command line for the eclipse executable?
Eclipse no longer treats your project as a C++ project. Choose menu File/New/Convert to a C/C++ project. It takes a while to index the source code. worked for me
I started with trying Josh Kelleys and mmmmms answers without any luck, but I finally fixed it by checking my include paths.
One way to see them are in the Project Explorer, expand project and there should be an entry "Includes". Inside that, check for a small yellow warning triangle on each include path. If that triangle is present eclipse most likely doesn't recognize the path.
The include paths are edited through right-clicking on "Your project" in the Project explorer, then choose "Properties" --> C/C++ General --> Paths and Symbols --> Includes.
I see three language options, Assembly, Gnu C, Gnu C++. Choose the correct one before starting to add paths (likely Gnu C++). After adding all the paths, -->Apply --> Ok and rebuild index if you're asked to.
My erroneous workspace paths looked like MyProject/MyProject/folder when it was supposed to be MyProject/folder.
For me the "Problems"-view is always slow to update, even after rebuilding index. To be sure that the error is still there, double-click the problems entry so that eclipse opens/reloads the file in question. This often seems necessary for me to update the "Problems" view.
I don't really know if it was eclipse or my scm that messed it up. Anyway, hope it helps someone!
I use Luna and builds with an external makefile.
We've got a program which runs separately, executed with an execvp command. So it needs a main method, but I believe that poses a problem to eclipse with a managed make. Do we have to keep this code segregated into a separate project, or is there a way to incorporate it into the same eclipse project?
Create a project for each executable that has a main() function, and create an additional project to represent the software as a whole (a "container" project of sorts). Eclipse allows you to specify projects as dependencies of other projects, and in this case you will want to set up the container project to list the other projects as "Referenced Projects".
To do this, create the container project, then right-click on the project in the left-hand column (project explorer) and click "Properties". A dialog box will appear. Select the "Project References" item in the list on the left-hand side and you will see a list of all projects that Eclipse is currently working with. Check the boxes next to the projects for your individual executables, then click OK. Now, when you perform a build on the container project, Eclipse should automatically perform a build on these dependent projects as well.
When using sub-projects in this manner, I have (personally) found it useful to create a working set that includes the container project and all of the sub-projects (this can make searching the entire software project easier).
Keep it in the same project and use preprocessor defines which you define differently depending on what kind of main you want to include in the current project. Here the mains are in the same file, but they can of course reside in different files.
#if defined(MAIN_ONE)
int main()
{
// Do stuff
}
#elif defined(MAIN_TWO)
int main()
{
// Do some other stuff
}
#endif
If the makefile being invoked doesn't compile the 2 main() methods into the same executable, it won't cause a problem. I don't know how eclipse projects are handled - if it's like VS, where "project" means a single executable or library, and "solution" is a group of "projects", then it would seem you'd need more than one project. If, OTOH, a "project" can contain different "subprojects" where a "subproject" is an executable or library, you should be able to handle that easily.
I am not aware of any easy way to build two mains using Eclipse build system. The smallest change you need to do might be to move to makefiles and use makefile targets to build.
Instead, I'd advise you to move to using CMake. CMake can be used to generate makefiles to be used with eclipse. The advantage you get from using CMake is that you can easily state how to build the libraries and link the libraries to form the executables. CMake can generate builds for Eclipse, Visual Studio, Code Blocks, or makefiles (so you can use command prompt).
This is built in the C++ language. You would have to modify it to get your result. There is something to do 2 things at once if that is what you want.