简体   繁体   English

Visual C ++和gcc一样强大吗?

[英]Is Visual C++ as powerful as gcc?

My definition of powerful is ability to customize. 我对强大的定义是定制的能力。

I'm familiar with gcc I wanted to try MSVC. 我熟悉gcc我想尝试MSVC。 So, I was searching for gcc equivalent options in msvc. 所以,我在msvc中搜索gcc等效选项。 I'm unable to find many of them. 我找不到他们中的很多人。

controlling kind of output 控制输出类型

Stop after the preprocessing stage; do not run the compiler proper.
gcc: -E
msvc: ???

Stop after the stage of compilation proper; do not assemble.
gcc: -S
msvc: ???

Compile or assemble the source files, but do not link.
gcc: -c
msvc:/c

Useful for debugging 对调试很有用

Print (on standard error output) the commands executed to run the stages of compilation.
gcc: -v
msvc: ???

Store the usual “temporary” intermediate files permanently;
gcc: -save-temps
msvc: ???
  1. Is there some kind of gcc <--> msvc compiler option mapping guide? 是否有某种gcc < - > msvc编译器选项映射指南?
  2. gcc Option Summary lists more options in each section than Compiler Options Listed by Category . gcc选项摘要列出了每个部分中比按类别列出的编译器选项更多的选项。 There are hell lot of important and interesting things missing in msvc. msvc中缺少许多重要且有趣的东西。 Am I missing something or msvc is really less powerful than gcc. 我错过了什么,或者msvc实际上不如gcc强大。

MSVC is an IDE, gcc is just a compiler. MSVC是一个IDE,gcc只是一个编译器。 CL (the MSVC compiler) can do most of the steps that you are describing from gcc's point of view. CL(MSVC编译器)可以从gcc的角度执行您描述的大多数步骤。 CL /? gives help. 给予帮助。

Eg 例如

Pre-process to stdout: stdout的预处理:

CL /E

Compile without linking: 编译没有链接:

CL /c

Generate assembly (unlike gcc, though, this doesn't prevent compiling): 生成程序集(与gcc不同,这不会阻止编译):

CL /Fa

CL is really just a compiler, if you want to see what commands the IDE generates for compiling and linking the easiest thing to look at the the command line section of the property pages for an item in the IDE. CL实际上只是一个编译器,如果你想看看IDE生成什么命令来编译和链接最简单的事情来查看IDE中项目的属性页面的命令行部分。 CL doesn't call a separate preprocessor or assembler, though, so there are no separate commands to see. CL不会调用单独的预处理程序或汇编程序,因此没有单独的命令可供查看。

For -save-temps , the IDE performs separate compiling and linking so object files are preserved anyway. 对于-save-temps ,IDE执行单独的编译和链接,因此无论如何都会保留目标文件。 To preserve pre-processor output and assembler output you can enable the /P and /Fa through the IDE. 要保留预处理器输出和汇编器输出,可以通过IDE启用/P/Fa

gcc and CL are different but I wouldn't say that the MSVC lacks "a hell lot" of things, certainly not the outputs that you are looking for. gccCL是不同的,但我不会说MSVC缺乏“很多东西”,当然不是你想要的输出。

For the equivalent of -E, cl.exe has /P (it doesn't "stop after preprocessing stage" but it outputs the preprocessor output to a file, which is largely the same thing). 对于-E的等价物,cl.exe具有/ P (它不会“在预处理阶段后停止”,但它会将预处理器输出输出到文件,这在很大程度上是相同的)。

For -S, it's a little murkier, since the "compilation" and "assembling" steps happen in multiple places depending on what other options you have specified (for example, if you have whole program optimization turned on, then machine code is not generated until the link stage). 对于-S,它有点模糊,因为“编译”和“组装”步骤发生在多个位置,具体取决于您指定的其他选项(例如,如果您打开了整个程序优化,则不会生成机器代码直到链接阶段)。

For -v, Visual C++ is not the same as GCC. 对于-v,Visual C ++与GCC不同。 It executes all stages of compilation directly in cl.exe (and link.exe) so there are no "commands executed" to display. 它直接在cl.exe(和link.exe)中执行编译的所有阶段,因此没有“命令执行”显示。 Similarly for -save-temps: because everything happens inside cl.exe and link.exe directly, the only "temporary" files are the .obj files that cl.exe produces and they're always saved anyway. 同样对于-save-temps:因为一切都发生在cl.exe和link.exe中,所以唯一的“临时”文件是cl.exe生成的.obj文件,无论如何它们总是被保存。

At the end of the day, though, GCC is an open source project. 但最终,GCC是一个开源项目。 That means anybody with an itch to scratch can add whatever command-line options they like with relatively little resistance. 这意味着任何有痒痒的人都可以添加他们喜欢的命令行选项,但阻力相对较小。 For Visual C++, a commercial closed-source product, every option needs to have a business case, design meetings, test plans and so on. 对于商业闭源产品Visual C ++,每个选项都需要有商业案例,设计会议,测试计划等。 Every new feature starts with minus 100 points . 每个新功能都以零下100点开头

Both compilers have a plethora of options for modifying... everything. 两个编译器都有很多选项可以修改......所有内容。 I suspect that any option not present in either is an option for something not worth doing in the first place. 我怀疑任何一种选项中都没有的选项是首先不值得做的事情。 Most "normal" users don't find a use for most of those options anyway. 大多数“正常”用户无论如何都找不到大多数这些选项的用途。

If you're looking purely at the number of available options as a measure of "power" or "flexibility" then you'll probably find gcc to be the winner, simply because gcc handles many platforms other than Windows and has specific options for many of those platforms that you obviously won't find in MSVC. 如果你纯粹关注可用选项的数量作为“权力”或“灵活性”的衡量标准,那么你可能会发现gcc成为赢家,因为gcc处理Windows以外的许多平台并且具有许多特定选项您在MSVC中显然不会找到的那些平台。 gcc (well, the gcc toolchain) also compiles a whole lot of languages beyond C and C++; gcc(嗯,gcc工具链)也编译了C和C ++之外的许多语言; I recently used it for Objective-C, for example. 例如,我最近将它用于Objective-C。

EDIT: I'm with Dean in questioning the validity of your question. 编辑:我和Dean一起质疑你问题的有效性。 Yes, MSVC (cl) has options for the equivalent of many of gcc's options, but no, the number of options doesn't really mean much. 是的,MSVC(cl)有相当于许多gcc选项的选项,但不是,选项的数量并没有多大意义。

In short: Unless you're doing something very special, you'll find MSVC easily "powerful enough" on the Windows platform that you will likely not be missing any gcc options. 简而言之:除非你做一些非常特别的事情,否则你会发现MSVC在Windows平台上很容易“强大”,你可能不会错过任何gcc选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM