我正在编译一些我使用过push_back函数的c ++程序。最后我收到了这个错误:
/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));
}
答案 0 :(得分:1)
我使用以下(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.cc”:
// 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发行版进行任何其他更改。