为什么gcc可以编译C++;代码但不能链接? < >我知道C++代码应该用G++编译,而不是GCC。 但是为什么GCC仍然可以编译C++源代码,尽管源代码中有大量的C++关键字。 顺便说一下,我发现我甚至可以用GCC用所有C++代码来构建一个共享库。为什么?< P> G++是GCC,它只是自动链接到标准C++库。

为什么gcc可以编译C++;代码但不能链接? < >我知道C++代码应该用G++编译,而不是GCC。 但是为什么GCC仍然可以编译C++源代码,尽管源代码中有大量的C++关键字。 顺便说一下,我发现我甚至可以用GCC用所有C++代码来构建一个共享库。为什么?< P> G++是GCC,它只是自动链接到标准C++库。,gcc,Gcc,如果您的g++代码依赖于标准库(位于std命名空间中),那么您可以 使用g++命令,并且它是全自动的 使用GCC命令,并显式指定C++标准库( -LSTDC++ < < /LI>) 您可以从GCC手册页链接到-lstdc++。: For any given input file, the file name suffix determines what kind of compilation is done: file.c C source code which

如果您的g++代码依赖于标准库(位于
std
命名空间中),那么您可以

  • 使用g++命令,并且它是全自动的
  • 使用GCC命令,并显式指定C++标准库(<代码> -LSTDC++<代码> < < /LI>)
    您可以从GCC手册页链接到-lstdc++。

       For any given input file, the file name suffix determines what kind of
       compilation is done:
    
       file.c
           C source code which must be preprocessed.
    
       .
       .
       .
    
       file.h
           C, C++, Objective-C or Objective-C++ header file to be turned into
           a precompiled header.
    
       file.cc
       file.cp
       file.cxx
       file.cpp
       file.CPP
       file.c++
       file.C
           C++ source code which must be preprocessed.  Note that in .cxx, the
           last two letters must both be literally x.  Likewise, .C refers to
           a literal capital C.
    

    <>它不做的是自动链接到C++标准库。在这一点上使用
    g++
    是最简单的。

    如果要降低速率,请发表评论。@solotim,它确实有效。也许你错过了什么?或者您应该编辑您的问题,并指定错误。