Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[cdt-dev] Creating a new C project programmatically?

Hello All,

I'm working on an Eclipse plug-in for an MPI model checker which includes example code that I want to programmatically create MPI managed build projects with. I'm currently using CDT 5.0 and Ganymede, and have figured out how to create the project, add include paths, and libraries as well as set the binary parser, the build command, add requisite files to the project, etc.

My stumbling block has been adding a linker library path to the project, This seems like it should be relatively straight forward thing, but no luck. I've referenced some older questions that were similar to mine in some posts and newsgroups, and all basically suggested looking at the CDT project wizard code in the org.eclipse.cdt repository (an example -> http://dev.eclipse.org/mhonarc/newsLists/news.eclipse.tools.cdt/msg13677.html). Couldn't mine deep enough I guess to find it. Any clues where this could be found? Essentially I want the following in the resulting.cproject file:

<option id="gnu.c.link.option.paths.2071016552" superClass="gnu.c.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="/usr/local/lib/isp"/>
</option>

As an example, here is how I'm adding libraries (-l) to the project. This works great, but please correct me if I'm using an outdated model:

   private void addLinkerLib(IConfiguration cf, String libName)
   {
       String ext = "o";
       ITool cfTool = cf.getToolFromInputExtension(ext);

       // add to -l (libraries)
       String optLibsID = "gnu.c.link.option.libs";
       IOption libOption = cfTool.getOptionById(optLibsID);

       String[] libraries = null;
       try
       {
           libraries = libOption.getLibraries();
       } catch (BuildException be)
       {
           ISP_Utilities.showExceptionDialog(null, be);
ISP_Log.logError("Failed adding new library in ISP_Examples.addLinkerLib().", be);
       }
       // add library
       int len = libraries.length;
       String newLibraries[] = new String[len + 1];
       System.arraycopy(libraries, 0, newLibraries, 0, len);
       newLibraries[len] = libName;
       ManagedBuildManager.setOption(cf, cfTool, libOption, newLibraries);
   }

And here is what I want to do with the linker lib paths (very similar). I've also tried option.setValue(...) and option.setValuType(...). All attempts have ended up with a BuildException being thrown saying "Bad value for type". I know I'm missing something simple here. I feel like I'm blind though, from looking at this and lots of other related code so much.

   private void addLinkerLibPath(IConfiguration cf, String libPath)
   {
       String ext = "o";
       ITool cfTool = cf.getToolFromInputExtension(ext);
// add to -L (library search path)
       String optPathsID = "gnu.c.link.option.paths";
       IOption option = cfTool.getOptionById(optPathsID);
       String[] includePaths = null;
       try
       {
           includePaths = option.getIncludePaths();
       } catch (BuildException be)
       {
         ISP_Utilities.showExceptionDialog(null, be);
ISP_Log.logError("Failed adding new library path in ISP_Examples.addLinkerPath().", be);
       }
       // add include path
       int len = includePaths.length;
       String newIncludePaths[] = new String[len + 1];
       System.arraycopy(includePaths, 0, newIncludePaths, 0, len);
       newIncludePaths[len] = libPath;
       ManagedBuildManager.setOption(cf, cfTool, option, newIncludePaths);
   }

Many thanks to anyone who can give me some advice here

-Alan Humphrey






Back to the top