如何克服"undefined reference to _M_insert_aux()"?
How to overcome "undefined reference to _M_insert_aux()"?
我正在编译一些c++程序,其中我使用了push_back函数。最后,我得到了这个错误:
/usr/include/c++/4.4/bits/stl_vector.h:741: undefined reference to `std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::**_M_insert_aux**(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
在文件stl_vector.h中,你会找到_M_insert_aux,但是我找不到它的定义。
请给我建议如何克服这个问题。
代码片段:
for (table=lex->query_tables; table; table=table->next_global)
{
string table_db=table->db;
table_db += ":";
table_db= table_db+table->table_name;
current.tables.push_back(table_db);
DBUG_PRINT("Dip", (" %s: %s, %s",table->db, table->table_name, table->alias));
}
我复制了以下编译错误(main.cpp
):
#include <vector>
#include <string>
int main()
{
std::vector<std::string> v;
v.push_back(std::string("test"));
return 0;
}
编译器命令:
g++ -fno-implicit-templates main.cpp -o main
如果没有指定-fno-implicit-templates
选项,则编译。
检查是否指定了编译标志-fno-implicit-templates
,如果可能的话删除它
为了使用-fno-implicit-templates
构建,我将源代码更改为:
#include <vector>
#include <string>
//class template std::vector<std::string>; TYPO here: 'class' & 'template' wrong order
template class std::vector<std::string>;
int main()
{
std::vector<std::string> v;
v.push_back(std::string("test"));
return 0;
}
编辑:我下载了mysql 5.1.60,并使用您在评论中提供的configure
和make
命令成功构建了它。
然后编辑文件"sql_parse. xml"。
// Added these include directives before any other.
#include <vector>
#include <string>
// At the end of include directives added this explicit template
// instantiation.
template class std::vector<std::string>;
// Added the following lines into a random function.
std::vector<std::string> v;
v.push_back(std::string("1"));
然后我再次运行make
,它编译和链接成功。注意:我是用-fno-implicit-templates
编译的:除了对"sql_parse.cc"所做的更改外,我没有对mysql发行版做任何其他更改。
相关文章:
- Insert函数不适用于2 if语句C++
- 如何在C++向量中奇数元素前面加上值-1,我在使用insert函数时遇到了问题
- 为什么 gcc 会给我可能未初始化的警告 deque::insert 带有过滤范围
- 当通知迭代器参数初始化为空列表的开头时,list::insert 行为是什么?
- 为什么使用 <uint8_t>MSVC 2015 编译器的 std::vector::insert 比 std::copy 快 5 倍?
- 如果迭代器没有因插入而无效,则使用std::find和C::insert()是线程安全的
- 与C++std::map::insert行为相比,C#排序字典的效率
- std::list 的两个 insert() 方法签名之间的实现差异
- 为什么 std::set::erase 与 std::set::insert 不一致?
- 编译器如何区分"vector::insert"的两种变体?
- std::map 在 [] 上调用默认构造函数,在 insert() 上调用复制构造函数
- STL vector.insert 方法期望_InputIterator作为参数
- 从更新查询获取'Cannot insert duplicate key'
- C++STL中set的'insert'函数的原理是什么?
- std::map insert && hyperload 导致复制
- 为什么在以下示例中 std::map::insert 失败?
- 排序时在空 std::vector 上使用 insert()
- C boost :: bimap insert()方法不起作用
- 为什么 std::queue 没有实现 insert() 而 std::d eque 实现了?
- map.insert:"Invalid arguments"错误与 pair<enum,vector<*>>