如何在Visual Studio 2010中捕获cl.exe命令行? [英] How can I capture the cl.exe command line in Visual Studio 2010?

查看:164
本文介绍了如何在Visual Studio 2010中捕获cl.exe命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,该项目是我从一个makefile转换而来的,该makefile的一个源文件需要编译器提供的命令行选项.例如,当您使用program --help用gcc构建项目时,它将吐出用于编译程序的gcc命令行.

I have a project that I converted from a makefile that has a source file that expects the command line options from the compiler. For example for when the project was built with gcc if you did program --help it would spit out the gcc command line used to compile the program.

我如何在Visual Studio中做同样的事情,以便它吐出用于编译程序的cl命令行?基本上,我想按F7键(构建解决方案)并使整个过程自动化.我找不到它的宏.谢谢

How can I do the same thing in Visual Studio, so that it spits out the cl command line used to compile the program? Basically I want to hit F7 (to build solution) and have the whole thing automated. I can't find a macro for it. Thanks

编辑;我的意思是以编程方式,因此例如,当我运行程序以使其输出包含所使用的cl.exe命令字符串时,我想要.您可以在Configuration Properties > C/C++ > Command Line > All Options看到命令行,但是找不到它的宏,也无法以某种方式将其封装在文件中.

edit; I mean programatically, so for example I want when I run the program for its output to contain the cl.exe command string that is used. You can see the command line at Configuration Properties > C/C++ > Command Line > All Options but I can't find a macro for it or some way to encapsulate it in a file.

推荐答案

由于VS将基础构建系统切换为MsBuild命令行,如该对话框所示,该对话框仅在VS中以编程方式创建.甚至可能不是 exact 命令行传递给cl:MsBuild本身通过任务调用CL,因此与VS中显示的内容没有直接链接,也没有获取命令的方法排队.

Since VS switched the underlying build system to MsBuild the command line as shown in that dialog is created programatically within VS only. It might not even be the exact command line passed to cl: MsBuild itself invokes CL via a task and as such there is no direct link with what is shown in VS nor is there a way to get the command line out of it.

无论如何,没有 the 命令行,因为每个源文件可能具有不同的选项.此外,我怀疑您是否需要完整的命令行,包括绝对包含路径等.没有人对此感兴趣.现在,如果您巧妙地使用了 http://msdn.microsoft.com中的宏/en-us/library/b0084kay.aspx ,您可以自己重新创建命令行,因为大多数选项都在其中:

Anyway, there is no such thing as the command line since each source file might have different options. Furthermore I doubt you want the full commandline including the absolute include paths etc. Nobody is interested in that. Now if you make clever use of the macros from http://msdn.microsoft.com/en-us/library/b0084kay.aspx you can sort of recreate the command line yourself since most options are there:

std::string CompilerCommandLineOptions()
{
  std::string cmd;
  #ifdef _CHAR_UNSIGNED
  cmd += " /J";
  #endif
  #ifdef __cplusplus_cli
  cmd += " /clr";
  #endif
  #ifdef _CPPRTTI
  cmd += " /GR"
  #endif
  //etc
  return cmd;
}

注意:您确定值得花点时间吗?真的有人对命令行感兴趣吗?仅仅构建项目还不够.那么为什么不使用链接器选项呢?

Note: are you sure it's worth the hassle? Is there really somebody interested in the command line? It's not even sufficient to build the project. Why not the linker options as well then?

这篇关于如何在Visual Studio 2010中捕获cl.exe命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆