有什么不同? lang ++铛-std = c ++ 11 [英] What is the difference? clang++ | clang -std=c++11
问题描述
我一直错误地使用此命令,该命令在链接步骤失败:
I had been erroneously using this command, which failed at the link step:
$ clang -std = c ++ 11 -stdlib = libc ++ myInputFile.cpp
有人可以解释为什么clang提供C ++语言选项,以及为什么它无法链接吗? strong>为什么选项 -x c ++
或 -std = c ++ 11
不能完成与 clang ++
?谢谢!
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
或 clang ++
是一个编译器:它们都是 drivers ,它们分析输入参数并确定使用哪些命令行在哪些文件上调用哪些编译器/汇编器/链接器论点。两者之间的唯一区别是 clang
仅在执行链接的情况下针对C标准库进行链接,而 clang ++
链接到C ++和C标准库。
Technically, neither of the programs named clang
or clang++
is a compiler: they are both drivers that 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.
-x =< language>
选项将覆盖驱动程序程序用于确定源文件语言的试探法,它指示驱动程序为< language>
调用编译器。
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.
-std =< dialect>
选项选择您要使用的特定语言的方言。如果需要确保您的C ++程序可移植到旧的C ++ 98编译器,则可以使用 -std = c ++ 98
对其进行编译。 -std
仅适用于目标语言:它不会尝试编译例如汇编程序或Java形式的C ++ 98,只有驱动程序认为是C ++的源文件。
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++.
总之,有两种不同的驱动程序可以使选择变得容易要链接的库。有一些合理的用例可以编译C ++,但不能链接到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.
这篇关于有什么不同? lang ++铛-std = c ++ 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!