What is the difference? clang++ | clang -std=c++11

前端 未结 2 2038
执笔经年
执笔经年 2020-12-13 04:15

I had been erroneously using this command, which failed at the link step:

$ clang -std=c++11 -stdlib=libc++ myInputFile.cpp

Can anyone e

相关标签:
2条回答
  • 2020-12-13 04:41

    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.

    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.

    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++.

    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.

    0 讨论(0)
  • 2020-12-13 04:47

    Clang is the name of the whole compiler.

    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)

    The -std=c++11 option enables the new C++11 standard (as in g++).

    0 讨论(0)
提交回复
热议问题