newprint
newprint

Reputation: 7098

gcc compilation error, works fine in Visual studio 2008 C++

Getting compilation error in gcc, even though it works fine on Visual Studio C++

#include <iostream>
using std::cout;  // tried it, didn't work
using std::cin;   // tried it, didn't work
using std::endl;  // tried it, didn't work

using namespace std;

This is the error, I am getting while trying to compile it.

hw2_part2.cpp:(.text+0xa2): undefined reference to `std::cout'
hw2_part2.cpp:(.text+0xa7): 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*)'
hw2_part2.cpp:(.text+0xb6): undefined reference to `std::cout'
hw2_part2.cpp:(.text+0xbb): 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*)'
hw2_part2.cpp:(.text+0xca): undefined reference to `std::cout'
hw2_part2.cpp:(.text+0xcf): 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*)'
hw2_part2.cpp:(.text+0xde): undefined reference to `std::cin'

Upvotes: 0

Views: 739

Answers (1)

Michael Burr
Michael Burr

Reputation: 340506

Compile using g++ instead of gcc so you get the C++ library linked in.

See What's the difference between gcc and g++/gcc-c++? for more details if you're interested (though there's really not much more to it).

Upvotes: 13

Related Questions