是否可以在编译之前立即将代码注入翻译单元
我使用 MSVC++ 2008 和 2010 构建我的 C++ 代码库。是否有可能获取翻译单元,对其进行分析,在必要时插入一些代码,然后传递到编译过程?原始源代码不应受到影响。
当然,对于构建项目的开发人员来说,它应该是透明的。最后,它只会影响目标文件。 Visual Studio 非常强大。我想,应该有某种插件 API 或挂钩来做到这一点。请给我一个提示。
I build my C++ code base with MSVC++ 2008 and 2010. Is it even possible to get translation unit, analyze it, insert some code if necessary and then pass on to the compilation process? Original source code should not be affected.
Sure, it should be transparent for a developer who builds a project. Finally, it will only affect object files. Visual studio is very powerful. I guess, there should be some kind of plugin API or hooks to do that. Please, give me a hint.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管我不确定,但我相信这不可能如您所描述的那样。这肯定是不平凡的。唯一浮现在脑海中的类似项目是 OpenMP,但我的印象是微软是实现他们的项目的人它的版本。
我可以看到一个模板引擎,例如 Cheetah 就足够了。不过,您可能会放弃诸如代码完成和智能感知之类的花哨功能。
基本上,您将设置文件以使用自定义编译器在另一个文件中生成新代码。然后 C++ 编译器将编译生成的文件。坦率地说,我认为它使用起来并不优雅或令人愉快。
我已经使用 CMake 做过类似的事情,尽管我并没有将其作为通用工具。我为一些内容生成写了一篇。
也许如果您实际上描述了您想要做的一些细节,我们可以提供更好的解决方案。
I don't believe this is possible as you describe it, though I don't know for sure. It would certainly be non-trivial. The only similar project that springs to mind is OpenMP, but I got the impression that Microsoft was the one who implemented their version of it.
I could see a template engine such as Cheetah sufficing though. You would likely give up your bells and whistles like code completion and intellisense though.
Basically, you would set up the files to use a custom compiler to generate the new code in another file. The C++ compiler would then compile the generated files. I don't think it would be elegant or pleasant to use, to be frank.
I've used CMake to do similar things, though I did not target it as a general tool. I wrote a one off for some content generation.
Maybe if you actually describe some of the specifics of what you want to do we can offer a better solution.