Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Create CDT Project programmatically with multiple files

I have been trying to create CDT Project programmatically with multiple files and trying to get translation unit out of it. However, I always get an empty list in return, while extracting the translation units out of the project.Can someone guide me, what is the correct way of creating a CDT project with multiple files in it.

Currently I am using the following code which is not giving me correct results:

private ICProject createCDTProjectFromFiles(final File[] files)
throws OperationCanceledException, CoreException, FileNotFoundException {
final IProject proj = createCDTProject("Test Project 10");
mCdtProject = proj;"Created temporary CDT project at " + getFullPath(mCdtProject));

final IFolder sourceFolder = mCdtProject.getFolder("src");
sourceFolder.create(true, true, NULL_MONITOR);
final ICSourceEntry entrySrc = new CSourceEntry(sourceFolder, null, ICSettingEntry.RESOLVED);
// CDataUtil.createEntry(CDataUtil., String name, String value, IPath[] exclusionPatterns, int flags)
// CDataUtil
// entrySrc.
for (final File file : files) {
createCopyOfFileInProject(mCdtProject, sourceFolder, file);

final CoreModel model = CoreModel.getDefault();
final ICProject icdtProject = model.create(mCdtProject);
return icdtProject;

private static IProject createCDTProject(final String projectName)
throws OperationCanceledException, CoreException {
final CCorePlugin cdtCorePlugin = CCorePlugin.getDefault();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
final IWorkspaceRoot root = workspace.getRoot();

IProject project = root.getProject(projectName);
IndexerPreferences.set(project, IndexerPreferences.KEY_INDEX_ALL_FILES, IPDOMManager.ID_FAST_INDEXER);

final IProjectDescription prjDescription = workspace.newProjectDescription(projectName);

project = cdtCorePlugin.createCDTProject(prjDescription, project, NULL_MONITOR);
// Assert.assertNotNull(project);;

// Assert.assertTrue(project.isOpen());

return project;


Muhammad Hamiz Ahmed

Back to the top