Как преодолеть «неопределенную ссылку на _M_insert_aux ()»? - PullRequest
0 голосов
/ 29 декабря 2011

Я собирал какую-то программу на 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));
}

1 Ответ

1 голос
/ 29 декабря 2011

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...