I'd like eclipse to only run make in the directory the current file belongs to, not for the entire project. This becomes more important since the project is very big and make on the top level takes around 20 minutes. most of it is entering-leaving directories and checking if build is needed etc. So I have to manually open the directory in cmd and run make. So I'd like eclipse to do this in its build automatically process. Is that possible?
Try to play with Build directory option found in project properties -> C/C++ Build -> Builder Settings tab. The default value there is ${workspace_loc:/your_project}. However Eclipse provides rich set of predefined variables (see under Variables... button). Probably most interesting for you are these ones:
build_files
Returns the set of absolute file system paths whose modification caused the current build. A list of the characters, 'a' (added), 'c' (changed), 'r' (removed), 'f' (files only), 'd' (directories only), can be supplied as an argument to limit the file list to just those types of deltas. Defaults to all deltas.
selected_resource_loc
Returns the absolute file system path of the selected resource.
Other places where you could try to use these variables are Make build target options in Behaviour tab.
If you can add your build step to the External tools configuration, you could create a manual builder from that.
The External tools configurations are set similarly as the Run configurations, but allow executing different kind of steps (e.g. shell, Ant - I am reasonably sure, make-files can also be supported, but I don't use them - if not, then you can add a shell script that runs the make-file).
To set this up you have to go to the project properties (Right click on the project, select Properties), then go to the Builders page, and add a new builder, that is created from an External tool configuration.
I hope I was clear enough for this to work.
Select your project, open Properties -> Builders. Uncheck the builders that you don't want to run automatically anymore. Hit "New..." and select "External Program".
Now you can specify what command shall be run automatically each time the project is built. To have the parent directory of the currently selected file as an argument for your build command, you may use ${selected_resource_loc}\... See the Variables button for more such place holders that can be resolved at runtime.
Afterwards you may want to configure the "refresh" tab, if you also want to see newly created files in your project explorer. And if everything works well after some trial and error, you may also want to look at the "Build Options" tab to have it run in the background.
Related
PAIN POINT:
Using Eclipse CDT - the launch configs I need are rather complex (little settings that are non-default values and other misc things) too many little things to remember, and easy to skip then stuff does not work. I want to be able to semi-automate this process in project makefiles.
Background:
I have multiple projects, not stored in the workspace (my users "import the project"). In some cases projects are some what generated (they are external makefile projects.
Requirement: Specifically depending on what build configuration is required the launch config needs to change/tweak, the external Makefile can do that, or I can create one launch file for each config. Or I can pre-populate them when I create the project
[example is normal development, debug/release but with unit-test variations]
The user might tweak the settings of course and want to save them.
Requirement: So that the launch files "travel with the project" - I want to check the into GIT, thus I want the .launch files kept in the same directory as the .project and .cproject files - as described here (thus they can be checked in and things are "self contained)
Store run configuration with project in Eclipse
PROBLEMS and QUESTIONS
1) Given existing launch configurations files (.launch files) in the ".project" directory, how can I browse/select from the list of existing ones that Eclipse does seem to previously know about.
{Example: Create a launch config called "FOO", copy this to "BAR", edit the BAR config file, replacing internal occurrences of FOO with BAR)
The BROWSE button in the "common" tab lets me select a directory to save but does not allow me to select an existing file
2) How can I tell eclipse File (X) is the default launch configuration for this project, or config(X) uses file(A) and config(Y) uses file (B)
3) Is there a way within the ".project" or ".config" or ".cproject" files to specify where to look for launch configurations, where to offer them?
4) Sure would be nice to have a file (or place in the .project, or .cproject) file that says: Launch configs for this project are in this directory - offer the user a list based on the files present in that directory
bottom line:
I'm sort of stuck - I can create launch files "correctly" with all required settings but I seem to have no means to tell Eclipse to use select/use them.
No amount of automation here seems to work, and I end up having to go back to manually creating and humanly forgetting settings in the project files.
Places I've looked:
Sort of the issue but not exactly
https://superuser.com/questions/521537/remove-launch-from-run-debug-drop-down-in-eclipse
Below - ARM describes the IMPORT process, but in my case all ".launch" files are grayed out and not selectable I don't know why and that is a different problem
I'd like to not make this a multi-step process - also see above about removing stale launch configs - you end up with too many launch configs in the history.
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0446h/CJADBBIA.html
There are numerous other places but all seem to be "click here" or "use this menu item" and not addressing the external file issue.
I have a C/C++ project which has some normal and some linked/virtual folders and it has been building just fine. Now that I've put it into perforce over VPN (the path of which I cannot modify), there is an ampersand in the path of the project that causes eclipse to fail when it gets to building the files in the linked folders (it appears eclipse builds an entire pathname for linked folder's files from the environment variables and passes that to the gnu compiler). I don't know if Perforce allows aliasing of workspaces (to get rid of the ampersand) but I can't find one. I've tried alt root but that doesn't seem to do anything useful. I've found that using the DOS command prompt subst F:
C:\perforce\pathwithampersand will allow the project to build in eclipse but now I loose the ability to utilize the Perforce plugin features. Although I can still manually check files in/out using the P4 client, it would be very useful if the ampersand problem was taken care of by eclipse. I've searched and searched but can't find anything about eclipse having a problem (or solution) with ampersand in the folder path. I'm using eclipse platform 4.2.1 and CDT 8.1.1 but cannot update to any later version(s) than those because they are part of a tool suite a vendor controls. Perforce plugin is 2013.1/server is 2009.1.
Go to the P4 Client Connection->Edit Current Workspace
Expand the depot tree until you see your project. Right mouse click on it and choose Include Special.
Click Files radio button and click the Save button.
That will cause a path name to be displayed next to your project under Client Expression. Click to the right of this path which will cause it to become editable. Cursor over to the part that includes the ampersand and delete it. Click the OK button.
P4 will then (eventually) ask if you want to update files to the new location (or something like that). Choose update and it will take some time to create the new folder and move the files there. It is unclear whether you need to log out of P4 for it to be completely enforced so the best solution is to do so (Connection->Log Off). It might leave the old directory so you can delete it at will and it will not appear the next time you start P4.
Some users found this sequence did not work this way so they had to click the "View workspace mapping as text" button on the workspace edit dialog and delete the ampersand. Click apply.
I set my java runtime options in Eclipse's Window > Prefs > Java > Installed JREs > Default VM Arguments. Since this setting is sufficient for all my main() entry points, I do not bother with customizing the "run configurations". It looks like nice flexibility but I probably will never need it. I was worried that I would have to repeat my VM arguments in the run configurations and so I started to copy my VM arguments but after an experiment it seems that I do not have to. Now I will have the opposite worry that I have some unintended customizations.
To eliminate the second worry, is there a way to eliminate the clutter visible in the Run drop down menu? What about the "Launch configurations" visible in the JAR export dialog? Is a run configuration the same thing as a launch configuration? How do I eliminate the multiple launch configurations?
I am on Eclipse Indigo on Ubuntu.
Edit After I manually delete all the run configurations, and proceed to do an export, buttons are greyed-out so I can't proceed. When I select the launch configuration drop-down, I end up with only one choice, from an unrelated project. I then created a run configuration for the real main entry point for the current project. I expect the clutter will return as I continue to use Eclipse.
One simple way would be to organize your projects by Eclipse workspace, which would limit the "run configurations" list only to the project referenced in a given workspace.
Switching workspaces would reset that list to the ones recorded for the projects of the new workspace.
Note: the OP's answer regarding launches file location isn't the only location possible.
The official one is:
${WORKSPACE}/.metadata/.plugins/org.eclipse.debug.core/.launches
But you can copy them enywhere else you want (as explained in "How do I save Eclipse launch profiles across workspaces?"), either by manually copying those files or by sharing them:
See "Which eclipse files belong under Version Control".
Once you know where they are saved, a simple delete is enough to make them disappear from the launcher menu.
The answer comes from #Francisco Puga
Experimental evidence shows that deleting "launches" seems to make run configurations disappear so it would seem that they might be synonymous.
In the build settings I have it define DEBUG when in the debug build configuration, so that I may make my code do separate things depending on which type of build it is.
However in Eclipse it darkens out the parts of the code which are excluded by the preprocessor, and this doesn't keep up when I change the setting (whether I'm currently building debug or release). So, I have a bunch of code which is perpetually darkened out, and the Eclipse indexer and other helpful features don't work inside of those areas.
How to fix? Has anyone else encountered this?
Update: Still having this issue. I eventually abandoned my unit-test build configs and simply put that functionality into a command-line switch. Just so that I could get indexing to work while I write my unit tests.
You have to set the option "Build configuration for the indexer" to "Use active build configuration" in the projects C/C++ indexer preferences. Open the properties panel for the project, go to c/C++ General and Indexer and enable project specific settings and change the radiobutton on the bottom to "Use Active build configuration".
Of course you can also set this in the global properties panel of Eclipse to change this setting for all projects.
Go to your project's Properties, then go to C/C++ General -> Paths and Symbols -> Symbols. Add your defines there and it will work.
If you want to change the defines for your system based on build configuration, you need to do as dgrant said here: "Project properties and select C/C++ General -> Paths and Symbols then select the Symbols tab", but you need to make sure you have the correct configuration selected at the top of your window. Also be sure when you add the symbol to the list that you DON'T check the "add to all configurations" checkbox.
If you want your correct set of symbols to be parsed by CDT in your editor, you'll also need to make sure you have the correct build configuration active as well. To do that, right-click on your project and select Build Configurations -> Set Active -> and select the build configuration you want to make active. CDT will now parse all the files as if this build configuration were active instead, using the global symbols you defined in the last step.
There is a problem I've seen with every version of Eclipse where it doesn't always decide to rebuild your index files immediately. To get it to do so, you can either start a build (the build doesn't actually have to complete), or you can right-click on your project and go to Index -> Rebuild. Both cause an immediate re-indexing to occur. You shouldn't need this, however. I can confirm that simply changing the build configuration as described in step 2 above will cause an #ifdef I have in my code which checks for a symbol defined only in one of my build configurations to immediately become greyed-out or un-greyed-out, as it should.
Check provider: -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> Providers -> CDT Managed Build Settings Entries. It should be enabled.
Check if defined symbol is in entries of this provider.
Indexer is optional.
My satisfactory solution has been to move away from Eclipse to editors with a working libclang plugin: Sublime Text, Vim.
For an intelligent IDE for C/C++, one probably can't go wrong with XCode or MSVC.
I'm using a ruby script to help generate a .c file based on another .c file (for a test harness called Unity).
The script runs using the pre-build option, updates the file, but the cproject doesn't see the upadted file as being touched so doesn't rebuild with it.
Using F5 updates it but I'd like to do this manually.
I can't see how to make this happen.
I had the same issue generating a C file from a Python script.
What I ended up doing is to create a special Builder for that file.
If you go to the project properties, go on the Builders tab and click New. Then select Program. You can fill all the information there. The important part is to go on the Refresh tab and select Refresh resources upon completion.
I also found it useful to unselect the stdio ("Allocate Console" in Build Options tab) so that it doesn't clear the console after a build.
the only drawback of that method is that the Builder doesn't pick-up dependencies and is called all the time.