undefined reference to 'std::cout'

前端 未结 4 1695
囚心锁ツ
囚心锁ツ 2020-11-28 18:03

Shall this be the example:

#include 
using namespace std;
int main()
{
    cout << \"Hola, moondo.\\n\";
}

It throws

4条回答
  •  盖世英雄少女心
    2020-11-28 18:57

    Compile the program with:

    g++ -Wall -Wextra -Werror -c main.cpp -o main.o
         ^^^^^^^^^^^^^^^^^^^^ <- For listing all warnings when your code is compiled.
    

    as cout is present in the C++ standard library, which would need explicit linking with -lstdc++ when using gcc; g++ links the standard library by default.

    With gcc, (g++ should be preferred over gcc)

    gcc main.cpp -lstdc++ -o main.o
    

提交回复
热议问题