undefined reference to 'std::basic_string
来源:互联网 发布:money pro for mac 编辑:程序博客网 时间:2024/05/31 05:27
[c/c++][gcc] undefined reference to 'std::basic_string ...'
我在使用 gcc 对c++ 文件进行编译的时候 (命令是 "gcc HelloWorld -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<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
- c/c++][gcc] undefined reference to 'std::basic_string ...
- [c/c++][gcc] undefined reference to 'std::basic_string ...'
- cmake _GLIBCXX_USE_CXX11_ABI undefined reference std::__cxx11::basic_string
- : error: undefined reference to `cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_t
- undefined reference to `std::cin'
- undefined reference to `std::cout'
- gcc says: undefined reference to 'std::cout'
- gcc:undefined reference to 'std::cout'
- undefined reference to `std::allocator<char>::~allocator()'
- undefined reference to `std::ios_base::Init::Init()
- undefined reference to `std::ios_base::Init::Init()
- undefined reference to `std::cout'等错误
- C++编译出现binding ‘const string {aka const std::__cxx11::basic_string<char>}’ to reference of type ‘std
- undefined reference to std::basic_ostream<char @GLIBCXX_3.4.9
- undefined reference to `std::__detail::_List_node_base@GLIBCXX_3.4.10
- stlport使用error: undefined reference to 'std::__throw_bad_alloc()'问题
- output.cpp:(.text+0x3a29): undefined reference to `std::basic_ostream<char, std::char_traits<char>
- 开源PhoneGap版图书商城
- Ubuntu系统中eclipse插件sqlexplorer_plugin-3.6.1_SR6的安装和配置
- 计算任意一天是星期几的问题
- FFmpeg windows平台编译
- 数据库创建视图时如何指定自定义列的类型
- undefined reference to 'std::basic_string
- Android中获取应用程序(包)的大小-----PackageManager的使用(二)
- 双机热备常识
- Linux和Win的换行
- Android ListView分页时出现java.lang.ClassCastException: android.widget.HeaderViewListAdapter异常
- 爱 不说再见
- JS获取URL参数方法
- SQL Server 2008 Partition 测试
- Git命令