有什么不同?叮当++ | 铿锵 -std=c++11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20047218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference? clang++ | clang -std=c++11
提问by djwbrown
I had been erroneously using this command, which failed at the link step:
我一直错误地使用这个命令,它在链接步骤失败:
$ clang -std=c++11 -stdlib=libc++ myInputFile.cpp
$ clang -std=c++11 -stdlib=libc++ myInputFile.cpp
Can anyone explain why clang provides a C++ language option, and why it fails to link?Why don't the options -x c++
or -std=c++11
accomplish the same thing as clang++
? Thanks!
谁能解释为什么 clang 提供 C++ 语言选项,以及为什么它无法链接?为什么选项-x c++
或-std=c++11
完成与 相同的事情clang++
?谢谢!
采纳答案by Casey
Technically, neither of the programs named clang
or clang++
is a compiler: they are both driversthat analyze the input arguments and determine what compilers/assemblers/linkers to invoke on what files with what command line arguments. The only difference between the two is that clang
links against only the C standard library if it performs a link, whereas clang++
links against both the C++ and C standard libraries.
从技术上讲,这些程序都没有命名clang
或clang++
不是编译器:它们都是分析输入参数并确定使用哪些命令行参数对哪些文件调用哪些编译器/汇编器/链接器的驱动程序。两者之间的唯一区别是,clang
如果执行链接,则仅链接 C 标准库,而clang++
链接 C++ 和 C 标准库。
The -x=<language>
option overrides the driver programs' heuristics for determining source file language, it directs the driver to invoke the compiler for <language>
regardless.
该-x=<language>
选项覆盖驱动程序确定源文件语言的试探法,它指示驱动程序<language>
无论如何调用编译器。
The -std=<dialect>
option picks which dialect of a particular language you want to use. If you need to ensure that your C++ program is portable to an old C++98 compiler, you can compile it with -std=c++98
. -std
only applies to the target language: it won't try to compile e.g. assembler or java as C++98, only source files that the driver believes to be C++.
该-std=<dialect>
选项选择您要使用的特定语言的哪种方言。如果您需要确保您的 C++ 程序可移植到旧的 C++98 编译器,您可以使用-std=c++98
. -std
仅适用于目标语言:它不会尝试将例如汇编程序或 java 编译为 C++98,只会编译驱动程序认为是 C++ 的源文件。
In short, there are two different driver programs to make it easy to select which libraries to link against. There are reasonable use cases for compiling C++ but not linking against the C++ standard library.
简而言之,有两种不同的驱动程序可以轻松选择要链接的库。有一些合理的用例可以编译 C++,但不链接 C++ 标准库。
回答by Claudio
Clang is the name of the whole compiler.
Clang 是整个编译器的名称。
However, from a command-line point of view:
但是,从命令行的角度来看:
- Clang is the C compiler
- Clang++ is the C++ compiler (like g++ is a C++ compiler, whereas gcc is a C compiler)
- Clang 是 C 编译器
- Clang++ 是 C++ 编译器(就像 g++ 是 C++ 编译器,而 gcc 是 C 编译器)
The -std=c++11 option enables the new C++11 standard (as in g++).
-std=c++11 选项启用新的 C++11 标准(如在 g++ 中)。