How to bind STL in C ++ code?

I wrote the code in the sql_parse.cc MySql 5.5.7rc source file. There I used vector , allocator , etc., but the compiler is not related to the standard template library (STL). Can anyone suggest me what to do?

Here is the msg error:

 libsql.a(sql_parse.cc.o): In function `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> > > >::push_back(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': sql_parse.cc:(.text._ZNSt6vectorISsSaISsEE9push_backERKSs[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> > > >::push_back(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)]+0x74): 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&)' collect2: ld returned 1 exit status 
+6
source share
4 answers

You should have specified the command line. I suspect you are using gcc for reference, in which case you should either use g++ or add -lstdc++ .

+16
source

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&)'

This symbol is a member function of std::vector<std::string> and is a function template, so it must be created in your program, and not in the C ++ standard library.

Are you going with the -fno-implicit-templates option? Or using an explicit expression about instantiating (i.e. extern ) in your code and not providing a definition? This will prevent the compiler from instantiating the template.

If you tell the compiler not to provide implicit instances, you need to add an explicit creation for each link undefined:

 template void std::vector<std::string>::_M_insert_aux(std::vector<std::string>::iterator, std::string const&); 
0
source

I got stl code to compile with the following

 g++ -std=c++11 file.cpp -o prog 
0
source
 #ifndef GLOBAL_H #define GLOBAL_H #include<iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> using namespace std; #endif //GLOBAL_H 

Good start

-2
source

Source: https://habr.com/ru/post/902200/


All Articles