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
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.
I got my stl code to compile with the following
g++ -std=c++11 file.cpp -o prog
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&)'
That symbol is a member function of std::vector<std::string> and is a function template, so should be instantiated in your program, not in the C++ standard library.
Are you compiling with the -fno-implicit-templates option? Or using an explicit instantiation declaration (i.e. extern template) in your code and not providing the definition? Those would prevent the compiler from instantiation the template.
If you're telling the compiler not to provide implicit instantiations then you will need to add an explicit instantiation for each undefined reference:
template void std::vector<std::string>::_M_insert_aux(std::vector<std::string>::iterator, std::string const&);
#ifndef GLOBAL_H
#define GLOBAL_H
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#endif //GLOBAL_H
Is a good start
Related
The following code
#include <optional>
#include <string>
#include <variant>
constexpr bool USE_VARIANT = 1;
using T = std::conditional_t<USE_VARIANT, std::variant<std::string>, std::string>;
struct S
{
T t;
};
constexpr int func()
{
S s{"str"};
return 0;
}
constexpr int x = func();
int main()
{
}
fails to compile with GCC trunk (compiler explorer link) with the message
In file included from <source>:4:
<source>:21:23: in 'constexpr' expansion of 'func()'
<source>:19:1: in 'constexpr' expansion of '(& s)->S::~S()'
<source>:10:8: in 'constexpr' expansion of '((S*)this)->S::t.std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~variant()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:1408:28: in 'constexpr' expansion of '((std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Variant_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Variant_base()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:736:12: in 'constexpr' expansion of '((std::__detail::__variant::_Variant_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Variant_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Move_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Move_assign_base()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:682:12: in 'constexpr' expansion of '((std::__detail::__variant::_Move_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Move_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Copy_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Copy_assign_base()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:630:12: in 'constexpr' expansion of '((std::__detail::__variant::_Copy_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Copy_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Move_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Move_ctor_base()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:592:12: in 'constexpr' expansion of '((std::__detail::__variant::_Move_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Move_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Copy_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Copy_ctor_base()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:555:12: in 'constexpr' expansion of '((std::__detail::__variant::_Copy_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Copy_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Variant_storage<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::~_Variant_storage()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:481:17: in 'constexpr' expansion of '((std::__detail::__variant::_Variant_storage<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this)->std::__detail::__variant::_Variant_storage<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::_M_reset()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:471:23: in 'constexpr' expansion of 'std::__do_visit<void, __detail::__variant::_Variant_storage<false, __cxx11::basic_string<char, char_traits<char>, allocator<char> > >::_M_reset()::<lambda(auto:11&&)>, variant<__cxx11::basic_string<char, char_traits<char>, allocator<char> > >&>(<lambda closure object>std::__detail::__variant::_Variant_storage<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::_M_reset()::<lambda(auto:11&&)>(), (* & std::__variant_cast<__cxx11::basic_string<char, char_traits<char>, allocator<char> >, __detail::__variant::_Variant_storage<false, __cxx11::basic_string<char, char_traits<char>, allocator<char> > >&>((*(std::__detail::__variant::_Variant_storage<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >*)this))))'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:1782:26: in 'constexpr' expansion of '(& __v0)->std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::index()'
/opt/compiler-explorer/gcc-trunk-20211231/include/c++/12.0.0/variant:555:12: error: accessing value of 's.S::t.std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Variant_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Move_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Copy_assign_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Move_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>.std::__detail::__variant::_Copy_ctor_base<false, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::<anonymous>' through a 'const std::variant<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >' glvalue in a constant expression
555 | struct _Copy_ctor_base : _Variant_storage_alias<_Types...>
| ^~~~~~~~~~~~~~~
C++ errors are often difficult to understand, but this one just left me clueless.
If I use USE_VARIANT = 0, it compiles.
If I change it to
constexpr int func()
{
T t{"str"};
return 0;
}
it compiles with either value.
With
constexpr int func()
{
std::optional<T> t{"str"};
return 0;
}
it doesn't compile either.
So it seems that when a std::variant<..., std::string, ...> is instantiated in a class, it fails to compile. The same happens with a std::vector<char> instead of a std::string, but other classes (that don't allocate memory dynamically) seem to work fine.
Am I missing something or have I found a compiler/stdlib bug?
The bug has been fixed and the example now compiles.
The command:
g++ -o "webserver" ./webserver.o -lwtdbopostgres -lwtdbo -lwthttp -lwt -lboost_signals
The horrendous, horrendous output:
./webserver.o: In function `Wt::Dbo::Impl::QueryBase<Wt::Dbo::ptr<pool::db::Settings> >::statements(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int) const':
webserver.cpp (.text._ZNK2Wt3Dbo4Impl9QueryBaseINS0_3ptrIN4pool2db8SettingsEEEE10statementsERKSsSA_SA_ii[Wt::Dbo::Impl::QueryBase<Wt::Dbo::ptr<pool::db::Settings> >::statements(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int) const]+0x1b3): undefined reference to `Wt::Dbo::Impl::completeQuerySelectSql(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, std::vector<Wt::Dbo::FieldInfo, std::allocator<Wt::Dbo::FieldInfo> > const&, bool)'
webserver.cpp:(.text._ZNK2Wt3Dbo4Impl9QueryBaseINS0_3ptrIN4pool2db8SettingsEEEE10statementsERKSsSA_SA_ii[Wt::Dbo::Impl::QueryBase<Wt::Dbo::ptr<pool::db::Settings> >::statements(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int) const]+0x25c): undefined reference to `Wt::Dbo::Impl::createQueryCountSql(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, int, bool)'
Many, many more lines...
Extracting the error messages a bit:
undefined reference to `Wt::Dbo::Impl::completeQuerySelectSql
undefined reference to `Wt::Dbo::Impl::createQueryCountSql
undefined reference to `Wt::Dbo::Impl::createWrappedQueryCountSql
...
Why are these not found? It is being linked with -lwtdbo and -lwtdbopostgres, which is what the project settings came with. This is after I downloaded, compiled, and installed the latest wt versions manually. Previously I had gotten them using apt-get and I had a different set of errors, though still undefined-reference-related.
It's likely that libwtdbopostgres.so and libwtdbo.so aren't in your library path. Check your $LD_LIBRARY_PATH to see if the path those libs are located appears.
Alternatively try using -L to specific the path to your two libraries
ie:
g++ -o "webserver" -L/home/libs ./webserver.o -lwtdbopostgres -lwtdbo... etc..
I am trying to compile tokumx (mongodb fork with transactions) on mavericks. It compiles for some time and then errors out with this message:
Linking build/darwin/64/release/mongo/mongodump
Undefined symbols for architecture x86_64:
"std::tr1::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const", referenced from:
std::tr1::_Hashtable<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, true>::find(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const in configuration_variable_manager.o
std::tr1::_Hashtable<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, true>::_M_rehash(unsigned long) in configuration_variable_manager.o
std::tr1::__detail::_Map_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, true, std::tr1::_Hashtable<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >, std::allocator<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::_Select1st<std::pair<std::basic_string<char, std::char_traits<char>, std::allocator<char> > const, boost::function<mongo::Status (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::__detail::_Mod_range_hashing, std::tr1::__detail::_Default_ranged_hash, std::tr1::__detail::_Prime_rehash_policy, false, false, true> >::operator[](std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in configuration_variable_manager.o
mongo::InitializerDependencyGraph::addInitializer(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, boost::function<mongo::Status (mongo::InitializerContext*)> const&, 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> > > > const&, 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> > > > const&) in initializer_dependency_graph.o
"std::__detail::_List_node_base::_M_unhook()", referenced from:
mongo::DistributedLockPinger::_distLockPingThread(mongo::ConnectionString, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long long) in distlock.o
std::list<mongo::FieldRangeSetPair, std::allocator<mongo::FieldRangeSetPair> >::_M_erase(std::_List_iterator<mongo::FieldRangeSetPair>) [clone .isra.535] in queryutil.o
mongo::OrRangeGenerator::_popOrClause(mongo::FieldRangeSet const*, mongo::Collection*, int, mongo::BSONObj const&) in queryutil.o
mongo::OrRangeGenerator::popOrClauseSingleKey() in queryutil.o
mongo::threadpool::ThreadPool::task_done(mongo::threadpool::Worker*) in thread_pool.o
mongo::threadpool::ThreadPool::~ThreadPool() in thread_pool.o
mongo::threadpool::ThreadPool::~ThreadPool() in thread_pool.o
...
ld: symbol(s) not found for architecture x86_64
Anyone knows exactly whats going on there?
This is caused by a mismatch between the standard library headers and library version, it's similar to this report http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43882.
OSX compilation isn't strictly supported for TokuMX yet, but I've been working on it recently. Make sure you have the latest Xcode and command line tools installed, and try compiling again with --cc=cc --cxx="c++ -std=c++11 -stdlib=libc++" as arguments to scons.
If that doesn't work, please also provide the command you used to try to build, and all of the preceding output, this would be a question better suited to the mailing list I think.
for C++ basic types, it works
unordered_map<string, int> m;
unordered_map<string, int>::iterator itr;
string s;
itr = m.find(s);
It compiles with no problem.
However, when I try
unordered_map<set<string>, int> m;
unordered_map<set<string>, int>::iterator itr;
set<string> s;
itr = m.find(s);
The compiler complains something that I can't read. Does anyone know what is going on? Do I have to use exception here?
g++ output:
/tmp/ccdwrdVP.o: In function `std::__detail::_Hash_code_base<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::pair<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const, int>, std::_Select1st<std::pair<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const, int> >, std::equal_to<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::hash<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, false>::_M_hash_code(std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) const':
test_unordermap_find.cpp:(.text._ZNKSt8__detail15_Hash_code_baseISt3setISsSt4lessISsESaISsEESt4pairIKS5_iESt10_Select1stIS8_ESt8equal_toIS5_ESt4hashIS5_ENS_18_Mod_range_hashingENS_20_Default_ranged_hashELb0EE12_M_hash_codeERS7_[std::__detail::_Hash_code_base<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::pair<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const, int>, std::_Select1st<std::pair<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const, int> >, std::equal_to<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::hash<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<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::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, false>::_M_hash_code(std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) const]+0x37): undefined reference to `std::hash<std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >::operator()(std::set<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >) const'
collect2: ld returned 1 exit status
std::unordered_map is implemented by means of a hash table, so it needs a hash function that can be applied to its key type. The default hash function is the std::hash template:
template < class Key,
class T,
class Hash = std::hash<Key>,
class Pred = std::equal_to<Key>,
class Alloc = std::allocator< std::pair<const Key,T> >
> class unordered_map;
However, std::hash is not defined for std::set. Therefore you need to either provide a definition of std::hash<set<string>>, or else specify your own hash function using the third template parameter of unordered_map.
I have written a class using std::tr1::regex, and I don't know how to link it. I get (sorry for the large dump...) :
$ g++ DictReader.cpp -std=c++0x
/usr/include/c++/4.4/tr1_impl/regex:2255: warning: inline function ‘bool std::tr1::regex_search(_Bi_iter, _Bi_iter, std::tr1::match_results<_Bi_iter, _Allocator>&, const std::tr1::basic_regex<_Ch_type, _Rx_traits>&, std::tr1::regex_constants::match_flag_type) [with _Bi_iter = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, _Allocator = std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, _Ch_type = char, _Rx_traits = std::tr1::regex_traits<char>]’ used but never defined
/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
/tmp/ccgBkWlK.o: In function `DictReader::operator++(int)':
DictReader.cpp:(.text+0xb2a): undefined reference to `bool std::tr1::regex_search<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, char, std::tr1::regex_traits<char> >(__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::tr1::match_results<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::tr1::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >&, std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&, std::bitset<11ul>)'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1EPKcj[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(char const*, unsigned int)]+0x75): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
/tmp/ccgBkWlK.o: In function `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)':
DictReader.cpp:(.text._ZNSt3tr111basic_regexIcNS_12regex_traitsIcEEEC1ERKS3_[std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::basic_regex(std::tr1::basic_regex<char, std::tr1::regex_traits<char> > const&)]+0x60): undefined reference to `std::tr1::basic_regex<char, std::tr1::regex_traits<char> >::_M_compile()'
collect2: ld returned 1 exit status.
What should I link against?
This is a linker error, it does not found the function you are using. TR1 is still new so it may not be implemented everywhere. I recommend you to use the boost regex library instead.