开发者

Is it possible to inject code into translation unit immediately before compilation

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 bui开发者_StackOverflow中文版lds 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜