Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Help setting CDT Indexer include path programmatically(How to add include path to CDT indexer programmatically to avoid source annotations in Editor)
Help setting CDT Indexer include path programmatically [message #821762] Thu, 15 March 2012 19:46 Go to next message
Presanna Raman is currently offline Presanna Raman
Messages: 2
Registered: March 2012
Junior Member
Hi,
I am new to developing using CDT plug-in. I am currently using Eclipse Indigo to develop my plug-in. I was planning on making use of the features automatically available with CDT - content assist, error reporting, etc. But CDT always reports syntax errors - "Type '<Variable>' could not be resolved" and annotates the source for all definitions and variables unless they are defined in the same source file. This makes code readability very difficult. The project build successfully as it has its own build files where the Include path is correctly referenced..

I presume that this is due to the CDT indexer not having all the include paths available to it. I want to know how I can provide CDT with the include paths programmatically. It is not possible to provide the include paths via preferences as there are a lot of modules and they change across projects.

I looked online for a way to programmatically set the include path but I was not able to find any help or instructions. Any help with this will be appreciated.

With Regards,

Presanna Raman.

P.S. I have attached image of what I see in the editor. Note: The INT32 macro is resolved while the rest are not.
Re: Help setting CDT Indexer include path programmatically [message #821830 is a reply to message #821762] Thu, 15 March 2012 21:46 Go to previous messageGo to next message
Presanna Raman is currently offline Presanna Raman
Messages: 2
Registered: March 2012
Junior Member
I further searched online and found code similar to the following. But it does not seem to help me with setting the project Include path.

		ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project);
	        ICConfigurationDescription activeConfiguration = projectDescription.getActiveConfiguration();
	        ICFolderDescription folderDescription = activeConfiguration.getRootFolderDescription();
	        ICLanguageSetting[] languageSettings = folderDescription.getLanguageSettings();
	        
	        int id = 0;
	        for(int i=0; i<languageSettings.length; i++) {
	            String langId = languageSettings[i].getLanguageId();
	            if(langId.contains("org.eclipse.cdt.core.gcc")) {
	                id = i;
	                break;
	            }
	        }
	        ICLanguageSetting lang = languageSettings[id]; 
	        		//lang.setSettingEntries(ICSettingEntry.INCLUDE_PATH, enryList)
	        lang.setSettingEntries(ICSettingEntry.INCLUDE_PATH, lse);
	        projectDescription.setActiveConfiguration(activeConfiguration);
	        projectDescription.setCdtProjectCreated();
	        CoreModel.getDefault().getProjectDescriptionManager().setProjectDescription(project, projectDescription);


What I am doing wrong? I tried to find what each of these classes mean but I am having difficulty finding helpful documentation.

With Regards,

Presanna Raman.
Re: Help setting CDT Indexer include path programmatically [message #829510 is a reply to message #821830] Mon, 26 March 2012 11:41 Go to previous messageGo to next message
Slavian Petrov is currently offline Slavian Petrov
Messages: 2
Registered: March 2012
Junior Member
Hi Raman,

I have a similar issue with my plugin.
After a search in the CDT sources I found something that is working for me in:
Project: org.eclipse.cdt.ui
Class: org.eclipse.cdt.internal.ui.wizards.settingswizards#readSettings()

This is finally how I made it:

IProject project = ...
ICProjectDescription projectDescription = CoreModel.getDefault().getProjectDescription(project, true);
ICConfigurationDescription configDecriptions[] = projectDescription.getConfigurations();
for (ICConfigurationDescription configDescription : configDecriptions) {
	ICFolderDescription projectRoot = configDescription.getRootFolderDescription();
	ICLanguageSetting[] settings = projectRoot.getLanguageSettings();
	for (ICLanguageSetting setting : settings) {
		if (!"org.eclipse.cdt.core.g++".equals(setting.getLanguageId()))
			continue;
		List<ICLanguageSettingEntry> includes = new ArrayList<ICLanguageSettingEntry>();
		includes.addAll(setting.getSettingEntriesList(ICSettingEntry.INCLUDE_PATH));
		includes.add(new CIncludePathEntry("/my/local/include/path", ICSettingEntry.LOCAL));
		setting.setSettingEntries(ICSettingEntry.INCLUDE_PATH, includes);
	}
}
CoreModel.getDefault().setProjectDescription(project, projectDescription);

[Updated on: Mon, 26 March 2012 11:56]

Report message to a moderator

Re: Help setting CDT Indexer include path programmatically [message #941103 is a reply to message #829510] Fri, 12 October 2012 08:10 Go to previous messageGo to next message
TBT Andrew is currently offline TBT Andrew
Messages: 13
Registered: January 2012
Junior Member
I am also developing a eclipse plugin to write include paths programmatically. I used the above code.
But the C/C++Build->Paths&Symbols does not update with the new data.

When access the data using setting.getsettingEntries() I can see the newly added data. But can't see in the properties window or
in project explorer.
Re: Help setting CDT Indexer include path programmatically [message #941287 is a reply to message #941103] Fri, 12 October 2012 11:15 Go to previous messageGo to next message
Slavian Petrov is currently offline Slavian Petrov
Messages: 2
Registered: March 2012
Junior Member
Hi TBT Andrew,

I made a mistake in the code above - bad if (...)
This is how I made it finally:
if (!setting.getId().startsWith("cdt.managedbuild.tool.gnu.cpp.compiler"))
continue;
Re: Help setting CDT Indexer include path programmatically [message #1015765 is a reply to message #941287] Sat, 02 March 2013 13:13 Go to previous messageGo to next message
Krishnaraj Bhat is currently offline Krishnaraj Bhat
Messages: 3
Registered: March 2013
Junior Member
Hi Slavian Petrov,

I am developing an eclipse plugin. I want to add the include paths programmatically when creating a new project. I am not sure about where to include the piece of code mentioned in the above posts. Could you please let me know the point where should this code be initiated.

Regards,
Krishnaraj.
Re: Help setting CDT Indexer include path programmatically [message #1019112 is a reply to message #821762] Fri, 15 March 2013 04:03 Go to previous messageGo to next message
Krishnaraj Bhat is currently offline Krishnaraj Bhat
Messages: 3
Registered: March 2013
Junior Member
Hi Raman,

Could you please let me know where should I write the piece of code mentioned by you so that new projects created will include the "INCLUDE PATHS".

Regards,
Krishnaraj.
Re: Help setting CDT Indexer include path programmatically [message #1019113 is a reply to message #1015765] Fri, 15 March 2013 04:05 Go to previous messageGo to next message
Krishnaraj Bhat is currently offline Krishnaraj Bhat
Messages: 3
Registered: March 2013
Junior Member
No Message Body
Re: Help setting CDT Indexer include path programmatically [message #1423336 is a reply to message #821762] Sun, 14 September 2014 08:25 Go to previous messageGo to next message
Aravind Parvathala is currently offline Aravind Parvathala
Messages: 1
Registered: September 2014
Junior Member
As usual there is more than one way to do things.


What I did was to use the ScannerConfigurationDiscoveryProfile extension point as below for my plugin.

<code>
<!-- C Projects -->
<extension point="org.eclipse.cdt.make.core.ScannerConfigurationDiscoveryProfile"
id="[your id here]"
name="[Some name]">
<scannerInfoCollector class="org.eclipse.cdt.managedbuilder.internal.scannerconfig.DefaultGCCScannerInfoCollector"
scope="project"/> <!-- Using CDT's internal scanner infor collectorm but you can define your own>
<buildOutputProvider>
<open/>
<scannerInfoConsoleParser class="[a class that implements org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser]"
compilerCommands="xap-local-xap-gcc" />
</buildOutputProvider>
<scannerInfoProvider providerId="specsFile">
<run
arguments="-E -P -v -dD ${plugin_state_location}/specs.c"
command="[your gcc compiler path]"
class="[use org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig2/GCCSpecsRunSIProvider.java or your own]"/>
<scannerInfoConsoleParser
class="[the scanner info console parser defined above]"/>
</scannerInfoProvider>
</extension>

</pre>


In the above the clas s that implements org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser is the key. It basically parses the the output of the scannerInfoProvider (i.e. the command [your gcc path] -E -P -v -dD specs.c).



Here various included files are parsed and added to the project. See the shutDown method for the CDT's default GCCSpecsConsoleParser.java

You can simply detect and add your own include directories here.
Re: Help setting CDT Indexer include path programmatically [message #1424120 is a reply to message #1423336] Mon, 15 September 2014 13:40 Go to previous message
Andrew Gvozdev is currently offline Andrew Gvozdev
Messages: 255
Registered: July 2009
Senior Member
Please check out https://wiki.eclipse.org/CDT/Developer/FAQ#How_do_I_contribute_Include.2FLibrary_paths_or_Macros_to_a_project_configuration_using_LanguageSettingsProvider_extension_point.3F. This is the preferred way of adding include paths.

Andrew
Previous Topic:Persistently store global environment variables
Next Topic:DSF-GDB Remote Debug - Attach To process- Always ask to select binary file
Goto Forum:
  


Current Time: Fri Oct 24 18:09:21 GMT 2014

Powered by FUDForum. Page generated in 0.01863 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software