【发布时间】:2013-09-09 12:18:25
【问题描述】:
写一个boost测试是否安装成功demo
#include<iostream>
#include<boost/lexical_cast.hpp>
int main(){
int a = boost::lexical_cast<int>("123456");
std::cout << a <<std::endl;
return 0;
}
编译错误
test.cpp:(.text+0x24): undefined reference to `std::cout'
test.cpp:(.text+0x29): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(int)'
test.cpp:(.text+0x31): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
test.cpp:(.text+0x39): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccG8Wb2k.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x61): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccG8Wb2k.o: In function `std::exception::exception()':
【问题讨论】:
-
你很可能调用的是
gcc而不是g++,区别在于后者默认情况下会在调用链接器时引入相关的c++数据。如果您出于某种未知原因想要使用gcc,请使用类似以下的gcc test.cpp -lstdc++ -
你能粘贴你的编译命令吗?你不是用 gcc 代替 g++ 吗?
标签: c++