New Eclipse CDT Project Template - How to Add a Library

Eclipse CDT Indigo has a new feature that allows you to add new C / C ++ template projects to a new project wizard. I figured out how to do this successfully until a certain point. I can create a basic project that just depends on simple source files, but now I would like to create a CPPUnit project, into which I would like to automatically add the CPPUnit library. For my life, I cannot understand how to achieve this goal. Does anyone know how?

+4
source share
2 answers

Sorry I'm late, but I had the same question on the same issue. I figured out a solution. This works for me, but I well know that this is probably not the way I would like. In your template.xml you can add the following process:

<process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues"> <simple name="projectName" value= "$(projectName)"/> <complex-array name="resourcePaths"> <element> <simple name="id" value="gnu.cpp.link.option.libs" /> <simple-array name="values"> <element value="dl" /> <element value="cppunit" /> </simple-array> <simple name="path" value="" /> </element> </complex-array> </process> 

The most important part is to know where to place the two dl and cppunit libraries. The gnu.cpp.link.option.libs key is valid for the GNU compiler toolchain, which is active on most Linux computers.

I extracted the key name from the Eclipse plugin org.eclipse.cdt.managedbuilder.gnu.ui_XXXXXXX . You can find it in the Eclipse plugins folder. If you need a key for another set of tools, I recommend opening the plugin.xml file. Here you should look for the attribute valueType="libs" . The corresponding id is the key to be manipulated in the process file.

If you also need to manipulate by searching the library, search for valueType="libPaths" . This will bring you to the gnu.cpp.link.option.paths key. You can add additional entries to the list using a process similar to the one shown above.

+5
source

It is AMAZING how difficult it is to find this material. In addition to viewing plugin.xml, all templates provide effective work on the implementation of these parameters:

Source Link

View Templates

  • plugins / org.eclipse.cdt.managedbuilder.gnu.ui_X.XXxxxxx.jar / templates / projecttemplates /

    • and then in each proj dir (for example, "HeloWorldCAnsiProject") find template.xml

GNU C features for viewing

  • Plugins /org.eclipse.cdt.managedbuilder.gnu.ui_X.XXxxxxx.jar/plugin.xml

Reverse engineering implementation example

The goal is to set the 'Cross GCC Compiler' โ†’ Optimization โ†’ 'Other optimization flags

  • create a dummy C project without customization
  • open properties. set the target field manually. I set the "Other optimization flags" to "COME_FIND_ME"

    enter image description here

  • open the .cproject file in the editor. find COME_FIND_ME. here is what i found:

     <option id="gnu.c.compiler.option.optimization.flags.1380831355" superClass="gnu.c.compiler.option.optimization.flags" value="COME_FIND_ME" valueType="string"/> 
    • this is then the type 'string' and 'id' gnu.c.compiler.option.optimization.flags.

    enter image description here

  • Search the plugin.xml list above for 'gnu.c.compiler.option.optimization.flags'. Here is what I found (on line 1120):

      <option name="%Option.Posix.Optimize.Flags" category="gnu.c.compiler.category.optimization" id="gnu.c.compiler.option.optimization.flags" valueType="string"> </option> 

    enter image description here

  • exit this sample project and go back to your template.xml template to which you want to add this. we want to add a default here, so let's do it. add:

     <process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value="gnu.c.compiler.option.optimization.flags" /> <simple name="value" value="-Omg_eclipse" /> <simple name="path" value="" /> </element> </complex-array> </process> 

and what is he.

useful links

Notes

This is where the MBS add / set functions live:

  • org.eclipse.cdt.managedbuilder.core.source_X.XXxxxxx.jar / org / eclipse / CDT / managedbuilder / templateengine / processes

enter image description here

Example full template file

finally, here is a snippet of code that can save you hours of cleaning up the Internet. this template.xml creates a new project by copying the main.c file and setting up three build options.

 <?xml version="1.0" encoding="ISO-8859-1"?> <template type="ProjTempl" version="1.0" supplier="stack_overflow" revision="1.0" author="Justin Reina" id="EXE" label="My C Project" description="set some stuff."help="help.html"> <process type="org.eclipse.cdt.core.CreateSourceFolder"> <simple name="projectName" value="$(projectName)"/> <simple name="path" value="bsp"/> </process> <process type="org.eclipse.cdt.core.AddFiles"> <simple name="projectName" value="$(projectName)"/> <complex-array name="files"> <element> <simple name="source" value = "main.c"/> <simple name="target" value = "main.c"/> <simple name="replaceable" value = "true" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringListOptionValues"> <simple name="projectName" value= "$(projectName)"/> <complex-array name="resourcePaths"> <element> <simple name="id" value="gnu.c.link.option.libs" /> <simple-array name="values"> <element value="corestuff" /> <element value="utilstuff" /> </simple-array> <simple name="path" value="" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.AppendToMBSStringOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value="gnu.c.compiler.option.optimization.flags" /> <simple name="value" value="-Omg_eclipse" /> <simple name="path" value="" /> </element> </complex-array> </process> <process type="org.eclipse.cdt.managedbuilder.core.SetMBSBooleanOptionValue"> <simple name="projectName" value="$(projectName)" /> <complex-array name="resourcePaths"> <element> <simple name="id" value="gnu.c.link.option.nostdlibs" /> <simple name="value" value="true" /> <simple name="path" value="" /> </element> </complex-array> </process> </template> 

To the Eclipse Foundation; next time I can just pay you half the salary for you to give me this information.

+4
source

Source: https://habr.com/ru/post/958355/


All Articles