GCC linker can't find standard library?

前端 未结 4 2019
臣服心动
臣服心动 2020-11-27 22:29

I\'ve been developing a school project in XCode. The final product has to be submitted in source code with a makefile, so I wrote a makefile and to start compiling that way,

4条回答
  •  无人及你
    2020-11-27 23:05

    To link C++ code, you need to use the g++ command, not the gcc command.

    When compiling, the gcc command knows that it's compiling C++ code because of the .cpp suffix (but it's a good idea to use the g++ command anyway).

    When linking, the gcc command just sees a bunch of .o files. The g++ command differs from the gcc command in that it knows where to find the C++-specific libraries.

    (The fact that the name gcc refers both to the command, which is usually used to compile C code, and the "GNU Compiler Collection" as a whole, can be a little confusing.)

提交回复
热议问题