6

I'm using Eclipse + CDT for a project. I'm using the "generate Makefiles automatically" option from my build settings. I have in one file the date and some values that must be actualized every time the project is compiled. But since I don't change every time this file the compiler doesn't refresh it. Is there any option so I can have a Phony target?

if I could just add some lines to the makefile will work rm -f *.o target but this will be removed the next time I update my project.

I found that in the settings >> c/c++ build >> behaviour there is an opportunity to write some clean variables. Could this help? I tried to write the file name but this does not work.

John Conde
  • 217,595
  • 99
  • 455
  • 496
dispatcher
  • 223
  • 3
  • 6

3 Answers3

8

You can give CDT a pre-build command. For me (3.6.2 on Linux):

  • ProjectProperties
  • C/C++ Build category
  • Settings sub-category
  • Build Steps tab
  • Pre-build steps pane
  • Enter a command to delete the object file in question (rm f.o, or somesuch)
bobbogo
  • 14,989
  • 3
  • 48
  • 57
  • thank you a lot. This is exactly what I was searching for. I'm sorry I could not vote you up, but I need 15 points status :) – dispatcher Sep 17 '12 at 13:01
  • @dispatcher: No worries. I hope this goes some small way to re-paying the help I've had from SO. – bobbogo Sep 17 '12 at 15:03
  • @dispatcher: See Eclipse bug 340300 (https://bugs.eclipse.org/bugs/show_bug.cgi?id=340300). Pre-build is broken for parallel builds, though there is an easy work-around. – bobbogo Sep 25 '12 at 10:54
  • I'm using CodeWarrior/Eclipse with CDT 8.1, on Windows. 'touch' seems to work ok here (touch "${ProjDirPath}/../Sources/version.c"). I guess it supports some linux style commands, not exactly sure how. Unfortunately for me this makes the entire project rebuild each time, and I haven't resolved that yet. – radsdau May 22 '18 at 03:03
  • I finally had success adding this to the post-build step command: ' & touch "${ProjDirPath}/../Sources/version.c"'. Not ideal, but it works. – radsdau May 22 '18 at 04:04
2

You can user make clean on Pre-build steps

0

I added the following to the Pre-build steps and it seems to work great:

del ${CWD}\addtional_dir\file.o