【问题标题】:gcc compilation error, works fine in Visual studio 2008 C++gcc 编译错误,在 Visual Studio 2008 C++ 中工作正常
【发布时间】:2012-02-29 20:56:32
【问题描述】:

在 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'

【问题讨论】:

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


    【解决方案1】:

    使用g++ 而不是gcc 进行编译,这样您就可以得到链接的C++ 库。

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

    【讨论】:

      猜你喜欢
      • 2011-03-22
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多