8

I have an Eclipse project that I need to auto-generate some files before compiling it. I do not want to put this auto-generated files in my repository, so each time I compile the projetct I perform a pre-build to auto-generate this files.

The problem is that this auto-generated files are *.c and *.h files, and in the first time I compile the project, the following happens (in this order):

  • pre-build: auto-generate some *.c and *.h
  • build: eclipse will not build this auto-generated files

If I compile again, this files will be compiled. Maybe this is happening because of the discovery process of what files eclipse will compile. Before initing compilation, we do not have this auto-generated *.c and *.h files.

In the second time we compile, we already have this auto-generated files, so this files are compiled.

user229044
  • 232,980
  • 40
  • 330
  • 338

2 Answers2

5

If you want full control over when exactly the custom build step takes place, which files need to be refreshed after it, the environment, the working directory etc.. do not specify it as a simple pre-build step. Go to the project properties -> Builders -> New... and choose "Program".

In the resulting dialog, you have much more control over the execution of your tool. For instance, you can make your tool run whenever the XML file is saved, and you can tell eclipse to refresh all the auto-generated files whenever it is run.

enobayram
  • 4,650
  • 23
  • 36
  • Thanks, this solved my problem. Only one note: if this problem happens on more than one project it will be necessary to duplicate this builder, as it seems it is not possible import the same instance. The builders names must be different (e.g.: adding (1) at the end). It is possible to make it easier to duplicate the builders by creating a template through 'Run > External Tools > Open External Tools Configurations -> New', but this will only work for other project members if the Workspace is under version-control (and usually it is not). – mMontu Feb 24 '15 at 19:53
  • @mMontu You can share the external tool configurations and keep them under version control if you go to the "Common" tab in the configuration setup and select the "Shared file" option. However, I think, in the end, no non-trivial build configuration should depend on any IDE's build system anyway. Ultimately, the right thing is to use a real build system such as CMake. – enobayram Feb 24 '15 at 21:03
  • Indeed, I wasn't aware of the "Shared file" option. I agree about avoiding IDE's build system, but it is not always possible when dealing with legacy (and large) projects. – mMontu Feb 25 '15 at 11:04
0

If I understand your question correctly, it seems that building your project the first time will auto-generate the necessary *.c and *.h source files, but the project will fail to fully build because these source files are not found immediately. After a small delay, Eclipse recognizes that there are new files added to the project and you can then build a second time and everything will proceed normally. Does that sound about right?

Assuming this is the case, my immediate thought is to write some sort of script or makefile so that all of these actions can take place in the proper order, with a single action. Depending on how dirty you want to get your hands, here's a link ;)

http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/concepts/cdt_c_makefile.htm

Stephane Beniak
  • 181
  • 1
  • 1
  • 7