Errors on compilation

190 views Asked by At

I tried to complile this project: https://github.com/ccshiro/corecraft I am use Ubuntu 16.04, i have installed: gcc 4.9, 5.0, 6.0; g++ 4.9, 5.0; clang; cmake3; and libsparsehash-dev .

I got this error:

[ 96%] Linking CXX executable mangosd
../game/libgame.a(Map.cpp.o): In function `sh_hashtable_settings<ObjectGuid, std::tr1::hash<ObjectGuid>, unsigned long, 4>::hash(ObjectGuid const&) const':
/usr/include/google/sparsehash/hashtable-common.h:65: undefined reference to `std::tr1::hash<ObjectGuid>::operator()(ObjectGuid) const'
collect2: error: ld returned 1 exit status
src/mangosd/CMakeFiles/mangosd.dir/build.make:244: recipe for target 'src/mangosd/mangosd' failed
make[2]: *** [src/mangosd/mangosd] Error 1
CMakeFiles/Makefile2:930: recipe for target 'src/mangosd/CMakeFiles/mangosd.dir/all' failed
make[1]: *** [src/mangosd/CMakeFiles/mangosd.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2

Here Map.cpp , here /usr/include/google/sparsehash/hashtable-common.h

I ve tried to google about "collect2: error: ld returned 1 exit status" error, and found that in code might be cyrrilics or non latinics symbols, but i didnt find something wrong in this 2 files above. On issue tracker i also found same error from another person https://github.com/ccshiro/corecraft/issues/5

I am not C++ programmer so i cant understand what wrong is here, can anyone help me with this?

1

There are 1 answers

0
James Poag On

What you are seeing is a linker error. Everything compiles fine, and then when the linker starts to stitch the code together it's missing a object that defines the functionality of the std::tr1::hash<ObjectGuid>::operator() hash operator. This is a template specialization that allows this object to be used as a unique key in a map (or hash set).

The template for the hash function is specified here. At first glance, I wasn't seeing why it shouldn't link, but then I realized that the linker is looking for std::tr1::hash<ObjectGuid> instead of std::hash<ObjectGuid>. Basically, it looks like your STL library is using TR1 which is an older pre-standard version of C++11.

Your first attempt should be to figure out how to specify that your compiler uses a newer version of the STL library. You should be able to add -std=c++11 to the CMAKE C++ flags (instead of -std=c++0X). Whether this means editing the CMakeLists.txt file to include the flag or making sure that your compiler was installed with a more modern version of STL.

That should fix the problem. I can think of another solution, but I suspect that you will get more errors by linking to an older version of STL.