memsharded / conan-protobuf

Google protocol buffers conan package
MIT License
1 stars 17 forks source link

Build fails on ubuntu 16.04 with gcc 5.4 #7

Open Phibedy opened 7 years ago

Phibedy commented 7 years ago

New ubuntu 16.04

//install basics
//automake/libtool is needed for protobuffers
sudo apt-get update
sudo apt-get install python python-pip build-essential make git cmake automake libtool
//install conan
sudo pip install conan
//add remote to conan
conan remote add lms http://mineforce.de:9300
conan install lms/2.0@lms/stable --build=missing

Error

[100%] Linking CXX executable bin/lms
liblmscore.so: undefined reference to `google::protobuf::internal::empty_string_'
liblmscore.so: undefined reference to `google::protobuf::internal::WireFormatLite::ReadString(google::protobuf::io::CodedInputStream*, std::string*)'
liblmscore.so: undefined reference to `pugi::xml_node::path(char) const' #Some other lib we have to fix
liblmscore.so: undefined reference to `google::protobuf::DescriptorPool::FindFileByName(std::string const&) const'
liblmscore.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteString(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
liblmscore.so: undefined reference to `google::protobuf::Message::InitializationErrorString() const'
liblmscore.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::Delete(std::string*)'
liblmscore.so: undefined reference to `google::protobuf::MessageFactory::InternalRegisterGeneratedFile(char const*, void (*)(std::string const&))'
liblmscore.so: undefined reference to `google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(int, std::string const&, google::protobuf::io::CodedOutputStream*)'
liblmscore.so: undefined reference to `google::protobuf::internal::StringTypeHandlerBase::New()'
liblmscore.so: undefined reference to `google::protobuf::io::CodedOutputStream::WriteStringWithSizeToArray(std::string const&, unsigned char*)'
liblmscore.so: undefined reference to `google::protobuf::Message::GetTypeName() const'
collect2: error: ld returned 1 exit status
CMakeFiles/lms.dir/build.make:95: recipe for target 'bin/lms' failed
make[2]: *** [bin/lms] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/lms.dir/all' failed
make[1]: *** [CMakeFiles/lms.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

lms/2.0@lms/stable: ERROR: Package '13a8d081f533db91339ab619a0f71485c8820c78' build failed
lms/2.0@lms/stable: WARN: Build folder /home/phoenix/.conan/data/lms/2.0/lms/stable/build/13a8d081f533db91339ab619a0f71485c8820c78
ERROR: lms: Error 512 while executing cmake --build . 

It works on ubuntu 14.04 with gcc 4.8 and 6.2.

owend commented 7 years ago

A quick fix is to add this to the CMakeLists.txt for your project

add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)

Although the conan docs suggest that it should also work, for some reason specifying libstdc++ (vs libstdc++11) doesn't trigger this flag for me, which caused the build to fail with the same error you're seeing. If I have time I'll track down the root cause.

memsharded commented 7 years ago

That is true, the add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0) is automatically defined only when used from a conanfile.py recipe with the CMake helper.

Check: https://github.com/conan-io/conan/blob/develop/conans/client/generators/cmake_common.py#L171

This only works when the CONAN_LIBCXX is defined, which is done by the CMake helper, typically used in the build() method of the recipe.

The root cause is the high decoupling between conan and the build system. When you install conan dependencies you specify some settings, and a conanbuildinfo.cmake is generated for those settings. But when you are building your project, your project settings must match the installed dependencies. For some of them, like the compiler and compiler version, the conanbuildinfo.cmake already implements some checks, but not for the libcxx.

I have added an issue (https://github.com/conan-io/conan/issues/1202) to the main conan repo, to try to improve this (even if it doesn't look easy without breaking the low coupling). Thanks for the feedback!

owend commented 7 years ago

Thanks for noticing! :) What's strange about this is that I built all dependencies from source with the same compiler and no specific settings or overrides, but still ended up with two different CXX11 versions somehow. I checked the conaninfo.txt file in the build dir of the Protobuf dependency and everything matched. Happy to provide any further details if you need them.