I need to use a specific file as "gdb" executable in Eclipse. In the "Debug Configurations" window, "Debugger" tab for a C/C++ Application, one can specify the executable through path. I would expect it is also possible to refer to the executable using a Eclipse environment variable but I cannot find the proper way to write this.
I have declared DEBUG_EXEC as Eclipse environment variable through: Window -> Preferences -> General -> Workspace -> Linked resources. And made this variable point to a specific file on my harddrive.
How could I refer to this variable?
Is this possible?
This is an old post but it was highly ranked on Google, so here goes.
You can achieve what you want by creating your variable in Preferences -> Run/Debug -> String Substitution.
If you create a variable called gdb_path, you can then refer to it in the Debug Configuration as ${gdb_path}. It will also appear in the list of variables when clicking the Variables button next to the GDB Command text field.
Related
How can I append or prepend a custom directory to the PATH environment variable in Eclipse CDT?
I am referring to the environment variables which can be specified at these locations:
for the C/C++ build environment
for C/C++ launch configurations
for external tool launch configurations
The custom directory should be prepended or appended to the PATH environment variable used by Eclipse itself (referred to as "native environment").
Attempting to set it the usual way (PATH=/my/custom/directory:${PATH}) does not work for launch configurations.
In a launch configuration you can use the env_var variable with the argument PATH:
${env_var:PATH}
Since plug-ins can contribute variables (e.g. git_branch by EGit) there is no documentation with a list of all variables and their arguments. In the New/Edit Environment Variable dialog, if you click Variables... and select the env_var variable, there is the following description at the bottom of the dialog (in my view the screenshot with env_var without arguments shown in the C/C++ Development User Guide is not correct here):
Returns the value of an environment variable. An environment variable
name must be specified as an argument.
In the C/C++ build environment, I would assume this would work too. But you've already found out that ${PATH} works here for sure.
Trying to manage post-build steps in Eclipse CDT project. Trying to copy newly builded file to directory ~/destination .
I could do following:
cp ${BuildArtifactFileBaseName}.so ~/destination
But I would like to escape from hardcoded parts there. For this reason I need to know:
Artifact extension Eclipse variable
Custom defined destination path variable
Where I can define custom variable for ~/destination ?
Where I can find whole list of Eclipse variables?
Will they be different for Java and C++ projects?
The Eclipse CDT build variables can be found at Window -> Preferences -> C/C++ -> Build ->Build Variables.
To see all variables, check the Show system variables checkbox.
Use the Add button on the Build Variables screen to add a new variable.
I don't have experience with Java on Eclipse, but probably there's an equivalent menu when compiling Java.
I have found that using the Eclipse "external tools" launch configuration is the best way to open my favorite editor on the current file in Eclipse, notably offering a one-time and super-flexible configuration versus the "Open With" menu, which I had tried to use beforehand and always found wanting, constraining, limiting, and requiring repetitive work for many file types. I set up this external tool as follows and this works great for files in my project:
Run:External Tools:External Tools Configurations...
New launch configuration
On the "Build" tab, un-check "Build before Launch"
On the Common tab, check "External Tools" under the "Display in favorites menu"
On the Main tab, enter "/usr/bin/myeditor" for the Location
Under "Working Directory" I am able to leave this blank
Under arguments ${resource_loc}
(At the top, in the "Name" field whatever I want the name to show up as)
I originally found this general technique for launching an external editor right here on stackoverflow.
So you can see ${resource_loc} or ${resource_path} is the one and only variable I need for this to work, and it does work great when I open a file located inside my Eclipse project and click the external tool. That part is fine.
But the problem I have just discovered occurs when I open a file that is not specifically listed in my project and then click the external tool button. It no longer works and I get an error dialog saying: "Variable references empty selection: ${resource_loc}."
Specifically, to reproduce this, I can create a new C++ "Hello World" project (CDT is included in my Eclipse along with Java) then add the line #include "/tmp/whatever.h" at the top of the one cpp file in the project and then right-click on "/tmp/whatever.h" and use the command "Open Declaration" and Eclipse kindly opens the file /tmp/whatever.h. Finally, I invoke my external tool intending to view whatever.h in my editor, and bang, that's when the problem occurs. (Before doing this I put a harmless line of commented text into /tmp/whatever.h.)
Before some SOer asks, no I am not actually trying to #include "/tmp/whatever.h". I am using this #include example as a specific way to show how the error can be reproduced. If you must know, in my case I actually observed the error when trying to open the editor while using Eclipse to browse framework files, files that are not part of my project.
I have already tried ${resource_path} to see if maybe that might have something in it in this context, but same error, and I have looked at the documented list of Eclipse launch variables here and again I don't see anything that looks like it would be more well-defined in the context of a file that is not part of the current project.
My assessment right now is that this is an unsolvable problem and likely just a limitation of trying to use the "External Tools" for this editor launching business. I only settled on that after using the default "Open With" menu in Eclipse for a while and finding the whole setup there highly unsatisfactory and requiring repeated configuration and actually IIRC it just would not work at all I believe in the context of my editor and controlling how many windows are created, whether one or many or one per project etc. Above, I simplified the launch for demonstration purposes.
OS: GNU/Linux Xubuntu 15.10.
Eclipse: Mars.1 Release (4.5.1) Build id: 20150924-1200
You can circumvent the "Workspace is the top-most Eclipse place" rule by linking files (or folders for that matter) in a project.
Example:
Create a new project:
File → New → Project → General → Project → Next → Project name: LinkProject → Finish
Create a file outside-workspace anywhere outside your Eclipse workspace dir.
Import this file as link:
Select LinkProject → File → Import... → General → File System → Next > → From directory: <as chosen for the file above> → Check ☑️ 📄 outside-workspace→ (⚠️ The next can be overlooked easily!) Advanced >> → Check ☑️ Create links in workspace → Finish
NB: I doesn't matter whether you uncheck ☐ Create link locations relative to: PROJECT_LOC ˅ or what you select from the list. ${resource_loc} is always the same. Just the file's/folder's Properties → Location: changes. There is a new property for linked files/folders: Resolved location which shows what ${resource_loc} is resolved to: an FQFN.
And, once you linked a file/folder in your project it is part of your project and you can also access it relatively, e.g. with ${workspace_loc:/LinkProject/outside-workspace}' which resolves to the FQFN, too.
See also Eclipse Platform User Guide – Linked resources.
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.
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.