2011-12-29 2 views
0

Я скомпилировал некоторую программу на C++, где я использовал функцию push_back. В конце я получаю эту ошибку:Как преодолеть «неопределенную ссылку на _M_insert_aux()»?

/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

Не могли бы вы опубликовать код, который производит это? – hmjd

+0

ок ... вот один фрагмент –

+0

для (таблица = lex-> query_tables; таблица; таблица = table-> next_global) \t { \t \t строка table_db = table-> дб; \t \t table_db + = ":"; \t \t table_db = table_db + table-> table_name; \t \t current.tables.push_back (table_db); \t \t \t DBUG_PRINT («Dip», («% s:% s,% s», table-> db, table-> table_name, table-> alias)); } –

ответ

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; 
} 

EDIT:

Я скачал 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: Я не сделал никаких других изменений в дистрибутиве mysql, кроме тех, что я сделал для «sql_parse.cc».

+0

Я сделал это, но его не работало ... Я удалил -fno-implicit-templates из файла конфигурации .. И добавил эта строка (шаблон шаблона std :: vector ;) но не работает ... Любые другие предложения plz ... –

+0

Вам нужно только добавить эту строку, если вы укажете '-fno-implicit-templates'. Вы запустили «make distclean» или подобное, чтобы удалить все ранее скомпилированные объекты? – hmjd

+0

да, сэр я очистил все предыдущие объекты ... Теперь я очистил эту строку и удалил -fno-implicit-templates, но все равно ошибка наступает. –

Смежные вопросы