Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to link STL in c++ code?

Tags:

c++

stl

I wrote some code in source file sql_parse.cc of MySql 5.5.7rc. There I have used vector, allocator, etc but the compiler is not being linked with Standard Template Library(STL). Can anybody suggest me what should I do?

Here is the error msg :

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
like image 368
Dipankar Saha Avatar asked Nov 23 '11 13:11

Dipankar Saha


1 Answers

You should've given the command line. I suspect that you use gcc for linking in which case you should either use g++ or add -lstdc++ option.

like image 187
Michael Krelin - hacker Avatar answered Sep 30 '22 06:09

Michael Krelin - hacker