您的位置:首页 > 编程语言 > C语言/C++

c/c++][gcc] undefined reference to 'std::basic_string ...

2012-07-19 17:12 696 查看
在编译c++代码是报以下错误

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::s

ize() const'

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::

operator[](unsigned int) const'

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::

operator[](unsigned int) const'

undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::

operator[](unsigned int) const'

undefined reference to `std::cout'

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*)'

undefined reference to `std::ios_base::Init::Init()'

undefined reference to `std::ios_base::Init::~Init()'

collect2: ld returned 1 exit status

解决方法是用如下命令进行编译(使用 -l 来连接 stdc++):

gcc HelloWorld.cpp -lstdc++ -o HelloWorld

另外,你也可以使用 g++, 效果是一样的, stdc++会被自动连接:

g++ HelloWorld.cpp -o HelloWorld
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐