gcc编译错误,在Visual Studio 2008 C ++中正常工作

时间:2012-02-29 20:56:32

标签: c++ visual-c++ gcc

在gcc中获取编译错误,即使它在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;

这是错误,我在尝试编译时遇到错误。

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'

1 个答案:

答案 0 :(得分:13)

使用g++代替gcc进行编译,以便链接到C ++库。

如果您感兴趣的话,请参阅What's the difference between gcc and g++/gcc-c++?了解更多详情(尽管实际上并不多)。