自动生成 C++使用 Visual Studio 在预构建事件中编写代码
我正在尝试使用 Visual Studio(具体来说是 VS 2005)中的预构建事件来运行 Python 脚本,该脚本将自动生成 .cpp 文件。我遇到的问题是,编译器似乎不知道这个文件是脏的,需要重新构建,直到构建完成后,这意味着我需要构建解决方案两次 - 一次生成此文件,然后再一次以便实际编译此文件。
在不太了解 C++ 编译器的内部工作原理的情况下,我天真的猜测是它会创建一个脏文件列表,需要在预构建事件运行之前重新编译这些文件,因此它会错过此自动-生成的文件,因为直到预构建事件之后才触及它。
如果预构建事件更改了该文件,是否有任何方法可以通知编译器需要重新编译该文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用 msvc 6。
尝试...
这就是我们使用 Oracle Pro*C 预处理器的方法。
效果很好。
I use msvc 6.
Try...
This is how we do it with the Oracle Pro*C preprocessor.
It works fine.
这不是我曾经做过的事情,但您可以尝试直接从预构建事件调用编译器(cl.exe)。
It's not something that I've ever done but you could try invoking the compiler (cl.exe) directly from your pre-build event.