如何克服"undefined reference to _M_insert_aux()"?

How to overcome "undefined reference to _M_insert_aux()"?

本文关键字:insert aux to undefined 何克服 克服 reference      更新时间:2023-10-16

我正在编译一些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,并使用您在评论中提供的configuremake命令成功构建了它。

然后编辑文件"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发行版做任何其他更改。