使用Visual Studio在预构建事件中自动生成C++代码

J. *_*man 5 c++ compiler-construction prebuild visual-studio pre-build-event

我正在尝试在Visual Studio中使用预构建事件(VS 2005具体)来运行Python脚本,该脚本将自动生成.cpp文件.我遇到的麻烦是,编译器似乎并不知道这个文件是脏,需要重建,直到之后的构建已经完成,这意味着我需要来构建解决方案两次 -一次产生这种文件,然后再一次,以便该文件实际编译.

在不太了解C++编译器的内部工作原理的情况下,我天真的猜测是它创建了一个脏文件列表,需要在预构建事件运行之前重新编译,因此它会错过这个自动生成的文件,因为它没有'直到预建活动之后才被触摸.

有没有办法通知编译器如果预构建事件更改它需要重新编译该文件?

Evi*_*ach 5

我用的是msvc 6.

尝试...

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.
Run Code Online (Sandbox Code Playgroud)

这就是我们使用Oracle Pro*C预处理器的方法.它工作正常.