• <tfoot id='NkpcE'></tfoot>

      <legend id='NkpcE'><style id='NkpcE'><dir id='NkpcE'><q id='NkpcE'></q></dir></style></legend>

      <i id='NkpcE'><tr id='NkpcE'><dt id='NkpcE'><q id='NkpcE'><span id='NkpcE'><b id='NkpcE'><form id='NkpcE'><ins id='NkpcE'></ins><ul id='NkpcE'></ul><sub id='NkpcE'></sub></form><legend id='NkpcE'></legend><bdo id='NkpcE'><pre id='NkpcE'><center id='NkpcE'></center></pre></bdo></b><th id='NkpcE'></th></span></q></dt></tr></i><div id='NkpcE'><tfoot id='NkpcE'></tfoot><dl id='NkpcE'><fieldset id='NkpcE'></fieldset></dl></div>
      • <bdo id='NkpcE'></bdo><ul id='NkpcE'></ul>
    1. <small id='NkpcE'></small><noframes id='NkpcE'>

      1. 使用 gcc 编译 C++ 程序

        时间:2023-09-19
              <tfoot id='qADCg'></tfoot>

                <bdo id='qADCg'></bdo><ul id='qADCg'></ul>
                <i id='qADCg'><tr id='qADCg'><dt id='qADCg'><q id='qADCg'><span id='qADCg'><b id='qADCg'><form id='qADCg'><ins id='qADCg'></ins><ul id='qADCg'></ul><sub id='qADCg'></sub></form><legend id='qADCg'></legend><bdo id='qADCg'><pre id='qADCg'><center id='qADCg'></center></pre></bdo></b><th id='qADCg'></th></span></q></dt></tr></i><div id='qADCg'><tfoot id='qADCg'></tfoot><dl id='qADCg'><fieldset id='qADCg'></fieldset></dl></div>

                <small id='qADCg'></small><noframes id='qADCg'>

                  <legend id='qADCg'><style id='qADCg'><dir id='qADCg'><q id='qADCg'></q></dir></style></legend>

                    <tbody id='qADCg'></tbody>
                  本文介绍了使用 gcc 编译 C++ 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  问题:如何用gcc编译器编译C++程序?

                  Question: How to compile a C++ program with gcc compiler?

                  信息.c:

                  #include<iostream>
                  using std::cout;
                  using std::endl;
                  int main()
                  {
                     #ifdef __cplusplus
                     cout << "C++ compiler in use and version is " << __cplusplus << endl;
                     #endif
                     cout <<"Version is " << __STDC_VERSION__ << endl;
                     cout << "Hi" << __FILE__ << __LINE__ << endl;
                  }
                  

                  当我尝试编译 info.c

                  $ gcc info.C

                  Undefined                       first referenced
                   symbol                             in file
                  cout                                /var/tmp/ccPxLN2a.o
                  endl(ostream &)                     /var/tmp/ccPxLN2a.o
                  ostream::operator<<(ostream &(*)(ostream &))/var/tmp/ccPxLN2a.o
                  ostream::operator<<(int)            /var/tmp/ccPxLN2a.o
                  ostream::operator<<(long)           /var/tmp/ccPxLN2a.o
                  ostream::operator<<(char const *)   /var/tmp/ccPxLN2a.o
                  ld: fatal: Symbol referencing errors. No output written to a.out
                  collect2: ld returned 1 exit status
                  

                  gcc 编译器不能编译 C++ 程序吗?在相关说明中,gcc 和 g++ 之间有什么区别.谢谢,

                  推荐答案

                  gcc 实际上可以很好地编译 C++ 代码.您收到的错误是链接器错误,而不是编译器错误.

                  gcc can actually compile c++ code just fine. The errors you received are linker errors, not compiler errors.

                  如果你把编译行改成这样:

                  Odds are that if you change the compilation line to be this:

                  gcc info.C -lstdc++
                  

                  这使它链接到标准的 C++ 库,然后它就可以正常工作了.

                  which makes it link to the standard c++ library, then it will work just fine.

                  然而,你应该让你的生活更轻松并使用 g++.

                  However, you should just make your life easier and use g++.

                  Rup 在 他对另一个答案的评论:

                  [...] gcc 将选择正确的后端编译器基于文件扩展名(即将将 .c 编译为 C,将 .cc 编译为 C++)并将二进制文件链接到标准 C 和 GCC 帮助程序库由默认与输入语言无关;g++ 也会选择正确的后端基于扩展,除了我认为它编译了所有 C 源代码作为 C++ 代替(即它同时编译.c 和 .cc 作为 C++),它包括无论如何,libstdc++ 在其链接步骤中输入语言.

                  [...] gcc will select the correct back-end compiler based on file extension (i.e. will compile a .c as C and a .cc as C++) and links binaries against just the standard C and GCC helper libraries by default regardless of input languages; g++ will also select the correct back-end based on extension except that I think it compiles all C source as C++ instead (i.e. it compiles both .c and .cc as C++) and it includes libstdc++ in its link step regardless of input languages.

                  这篇关于使用 gcc 编译 C++ 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:/usr/lib/libstdc++.so.6:未找到版本“GLIBCXX_3.4.15" 下一篇:__gxx_personality_v0 有什么用?

                  相关文章

                  最新文章

                • <legend id='20CCh'><style id='20CCh'><dir id='20CCh'><q id='20CCh'></q></dir></style></legend>

                • <tfoot id='20CCh'></tfoot>

                  <small id='20CCh'></small><noframes id='20CCh'>

                      <bdo id='20CCh'></bdo><ul id='20CCh'></ul>
                  1. <i id='20CCh'><tr id='20CCh'><dt id='20CCh'><q id='20CCh'><span id='20CCh'><b id='20CCh'><form id='20CCh'><ins id='20CCh'></ins><ul id='20CCh'></ul><sub id='20CCh'></sub></form><legend id='20CCh'></legend><bdo id='20CCh'><pre id='20CCh'><center id='20CCh'></center></pre></bdo></b><th id='20CCh'></th></span></q></dt></tr></i><div id='20CCh'><tfoot id='20CCh'></tfoot><dl id='20CCh'><fieldset id='20CCh'></fieldset></dl></div>