eclipse-cdt / cdt

Eclipse CDT™ C/C++ Development Tools
http://eclipse.org/cdt
Eclipse Public License 2.0
299 stars 198 forks source link

Add additional build artifacts, such as object files in .o format #394

Open baoruiqi opened 1 year ago

baoruiqi commented 1 year ago

Currently, we can select the type when creating a managed c/c++ project, such as executable files, or modify the build artifact of a project on the settings tab of the property page. However, there seems no way to get an unlinked object file by modifying these settings. For example, I can later disassemble this object file.

The following is a screenshot showing the project properties page. May it be possible to add some options to these entry in build artifact tab and implement the specific build process in the background?

image

Does such feature exist already and just not work since I'm not familiar with cdt. If not I hope to implement this feature myself. By searching the source code, I seem to find some content related to the type of obejct file, but due to lack of familiarity with the source code, I cannot fully discover the connection and realize the feature I need. please give me some suggestions. Thanks!

image

jantje commented 1 year ago

My 2 cent As you noticed the project type selected during project creation is linked to build artifact->artifact type project property. You can find these in the plugin.xml files for the extension point org.eclipse.cdt.managedbuilder.core.buildProperties the key org.eclipse.cdt.build.core.buildArtefactType

The exe artifact type is identified by the key org.eclipse.cdt.build.core.buildArtefactType.exe The static lib artifact type is identified by the key org.eclipse.cdt.build.core.buildArtefactType.staticLib The dynamic lib type is identified by the key org.eclipse.cdt.build.core.buildArtefactType.sharedLib afbeelding As you can see there is no "unlinked object file" there

These keys are then used in the project type definitions as you can see below afbeelding

So if you would want to add a "unlinked object file" target the first thing to do is to get a basic understanding of how plugin.xml works in eclipse and then a better understanding of the extension points defined in managed build

This is no small feat and before I would start to tackle this I would make sure the existing CDT can not deliver. One question I would ask myself: Why not use exe/shared lib/static lib as they all create the objects. Is the fact extra work is done a show stopper? Can I live with the error "unresolved main"? Can I live with an extra file that fixes the errors? ....

PS: Don't get me wrong: I do think your request is very valid.

baoruiqi commented 1 year ago

@jantje Thanks for your advice. As you said, this feature is not necessary.

In fact, I am learning the compilation process and try to find some real projects to deepen my understanding. As a code novice, I hope to familiarize myself with Eclipse plug-in development by reading the source code and trying to make certain modifications.

jantje commented 1 year ago

I came up with a way you can only compile objects in a exe, static lib or dynamic lib project. Here is how I did it: 1)Make a file named makefile.targets in the root of you project. The contents is objects :$(OBJS) 2) modify the build properties making the build target "objects" instead of "all" afbeelding