5

I'm trying to use a pre-build event in Visual Studio (VS 2005 to be specific) to run a Python script which will automatically generate a .cpp file. The trouble I'm running into is that the compiler doesn't seem to know that this file is dirty and needs to be rebuilt until after the build has finished, which means that I need to build the solution twice -- once to generate this file, and then once more once so that this file actually gets compiled.

Without knowing much about the inner workings of the C++ compiler, my naive guess is that it makes a list of dirty files which need to be recompiled before the pre-build event runs, so it misses this auto-generated file, as it hasn't been touched until after the pre-build event.

Is there any way to inform the compiler that it needs to recompile this file if the pre-build event changes it?

  • I've had this problem too and was never able to solve it. I tried setting the date into the past as part of the prebuild event, I tried setting dates on other files and deleting already compiled object files and such, nothing seemed to work. – SoapBox Feb 11 '10 at 17:04
  • All i have come up with is to make the pre-build executable detect that it's changed something. See this related question of mine : http://stackoverflow.com/questions/528494/use-domain-specific-language-files-inside-c-project – Benoît Feb 11 '10 at 21:38
  • Actually the executable i'm referring to is used in a custom build rule – Benoît Feb 11 '10 at 21:39

2 Answers2

5

I use msvc 6.

Try...

Put the python script into the project
give it a custom build step that invokes python on it,
to create the cpp file.

Add the cpp file to your project and do a rebuild all.

This is how we do it with the Oracle Pro*C preprocessor. It works fine.

EvilTeach
  • 28,120
  • 21
  • 85
  • 141
2

It's not something that I've ever done but you could try invoking the compiler (cl.exe) directly from your pre-build event.

Paul
  • 91
  • 2