Sarà questo l'esempio:
#include <iostream>
using namespace std;
int main()
{
cout << "Hola, moondo.\n";
}
Genera l'errore:
gcc -c main.cpp gcc -o edit main.o main.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `std::cout'
main.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<< <std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
main.o: In function `__static_initialization_and_destruction_0(int,int)':
main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
main.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld
returned 1 exit status make: *** [qs] Error 1
Inoltre, questo esempio:
#include <iostream>
int main()
{
std::cout<<"Hola, moondo.\n";
}
genera l'errore:
gcc -c main.cpp gcc -o edit main.o main.o: In function `main':
main.cpp:(.text+0xa): undefined reference to `std::cout'
main.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char,std::char_traits<char> >& std::operator<<<std::char_traits<char>>(std::basic_ostream<char,std::char_traits<char> >&, char const*)'
main.o: In function `__static_initialization_and_destruction_0(int,int)': main.cpp:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
main.cpp:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()' collect2: error: ld
returned 1 exit status make: *** [qs] Error 1
Nota: sto usando Debian Wheezy.
gcc -o edit main.o
non sa che main.o
saranno necessarie librerie di avvio C ++.
g++
invece digcc
.gcc
è per C e non ti darà accesso alla libreria standard C ++.