Automatically generating C ++ code in a pre-build event using Visual Studio

I am trying to use a pre-build event in Visual Studio (in particular, VS 2005) to run a Python script that will automatically generate a .cpp file. The problem I am facing is that the compiler does not seem to know that this file is dirty and needs to be rebuilt before the build is complete, which means I need to build the solution twice - once to create this file and then one more time so that this file really compiles.

Unaware of the internal operation of the C ++ compiler, my naive guess is that it creates a list of dirty files that need to be recompiled before the pre-build event is triggered, so it skips this automatically generated file, since it was not affected until the event ended pre-assembly.

Is there a way to tell the compiler that it needs to recompile this file if the pre-build event changed it?

+5
source share
2 answers

I am using 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.

Here's how we do it with the Oracle Pro * C preprocessor. It works great.

+5
source

, - , (cl.exe) .

+2

All Articles