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
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
相关文章推荐
- undefined reference to 'std::basic_string
- ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()'问题——gcc编译C++代码
- [c/c++][gcc] undefined reference to 'std::basic_string ...'
- ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()'问题
- ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()'问题
- gcc 编译错误:"undefined reference to 'sqrt'
- : error: undefined reference to `cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_t
- C++报错集合:在Linkeage时出现undefined reference to `SPTraderController::writeAplLog(bfl::BString const&)'
- MySQL connector C++在Linux下编译undefined reference to 'get_driver_instance'问题
- GCC版本不兼容导致的链接错误:undefined reference to `SomeFunction'
- 链接错误'undefined reference to'与gcc参数 -l -L -I
- 解决gcc 编译时报错"undefined reference to 'main'" 问题
- undefined reference to std::basic_ostream<char @GLIBCXX_3.4.9
- C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std
- Linux c++ error: undefined reference to 'dlopen' 解决办法
- error: undefined reference to 'android::AString::~AString()'
- gcc编译线程程序需带-lpthread选项(否则出错:undefined reference to `pthread_create')
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- gcc 共享库的时候显示.../crt1.o: In function `_start': (.text+0x18): undefined reference to `main'的错误
- 用gcc编译.cpp文件可能出现"undefined reference to `__gxx_personality_v0'"问题的解决