protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Building protobuf with -Dprotobuf_BUILD_SHARED_LIBS=ON not working?

Open rukyr97 opened this issue 2 years ago • 2 comments

What version of protobuf and what language are you using? Version: main Language: C++ / python (not sure if both or C++ only)

What operating system (Linux, Windows, ...) and version? WSL 2 (Ubuntu 22.04.1 LTS - Linux) What runtime / compiler are you using (e.g., python version or gcc version) gcc What did you do? Steps to reproduce the behavior:

  1. clone https://github.com/protocolbuffers/protobuf.git && cd protobuf
  2. git submodule update --init --recursive
  3. cmake . -Dprotobuf_BUILD_SHARED_LIBS=ON
  4. cmake --build .

What did you expect to see

Build protobuf.

What did you see instead?

Build had errors (stack trace below).

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs). [ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_import_lite.pb.cc.o [ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_import_public_lite.pb.cc.o [ 89%] Building CXX object CMakeFiles/tests.dir/src/google/protobuf/unittest_lite.pb.cc.o [ 89%] Linking CXX executable tests /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/testing/googletest.cc.o: in function google::protobuf::(anonymous namespace)::GetTemporaryDirectoryName()': googletest.cc:(.text+0x2ee): warning: the use of tmpnam' is dangerous, better use mkstemp' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::(anonymous namespace)::RepeatedField_Cords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x10af4): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10b40): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10b8c): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10bd8): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10c24): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10c41): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10d1d): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e3e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e5d): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Swap(google::protobuf::RepeatedFieldabsl::lts_20220623::Cord*)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10e69): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x10f2e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11005): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x110ca): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x111a6): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11298): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11374): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11457): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11540): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Clear()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1154c): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11635): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11641): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11a9e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11ab3): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::(anonymous namespace)::RepeatedField_TruncateCords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x11b6a): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11bb6): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c02): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c4e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11c66): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11d2b): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Truncate(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11d37): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11e2b): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Add(absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11e43): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11f08): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11fdf): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11fef): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Truncate(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x11ffb): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x121b5): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::(anonymous namespace)::RepeatedField_ResizeCords_Test::TestBody()': repeated_field_unittest.cc:(.text+0x1226e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12286): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1237c): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12394): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1248a): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x124a2): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12579): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12661): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1273d): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12819): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Get(int) const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12926): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Resize(int, absl::lts_20220623::Cord const&)' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x1293e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::empty() const' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12a24): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: repeated_field_unittest.cc:(.text+0x12d2e): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::~RepeatedField()' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::RemoveLast()': repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0x93): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::size() const' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0xa4): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Mutable(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE10RemoveLastEv]+0xc3): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::ExchangeCurrentSize(int)' /usr/bin/ld: CMakeFiles/tests.dir/src/google/protobuf/repeated_field_unittest.cc.o: in function google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::SwapElements(int, int)': repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii]+0x24): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Mutable(int)' /usr/bin/ld: repeated_field_unittest.cc:(.text._ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii[_ZN6google8protobuf13RepeatedFieldIN4absl12lts_202206234CordEE12SwapElementsEii]+0x38): undefined reference to google::protobuf::RepeatedFieldabsl::lts_20220623::Cord::Mutable(int)' collect2: error: ld returned 1 exit status gmake[2]: *** [CMakeFiles/tests.dir/build.make:2162: tests] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:1012: CMakeFiles/tests.dir/all] Error 2 gmake: *** [Makefile:146: all] Error 2

Anything else we should know about your project / environment

Previously I built protobuf with default cmake configuration. The building process of the open source project that required protobuf, had the errors below:

[ 77%] Building CXX object src/propagation/CMakeFiles/libpropagation-obj.dir/model/okumura-hata-propagation-loss-model.cc.o [ 77%] Linking CXX shared library ../../../build/lib/libns3-dev-opengym-default.so [ 77%] Building CXX object src/internet/CMakeFiles/libinternet-obj.dir/model/ipv6-header.cc.o /usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.cc.o): relocation R_X86_64_TPOFF32 against hidden symbol `_ZN6google8protobuf8internal15ThreadSafeArena13thread_cache_E' can not be used when making a shared object /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status gmake[2]: *** [contrib/opengym/CMakeFiles/libopengym.dir/build.make:141: ../build/lib/libns3-dev-opengym-default.so] Error 1 gmake[1]: *** [CMakeFiles/Makefile2:1278: contrib/opengym/CMakeFiles/libopengym.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs.... [ 77%] Building CXX object src/internet/CMakeFiles/libinternet-obj.dir/model/ipv6-interface-address.cc.o

Tried to change the way I build protobuf to include shared version of the protobuf lib. As a disclaimer, I'm new to this world of protobuf and cmake in general, so I apologize in advance if I'm doing a newbie mistake :)

rukyr97 avatar Jan 05 '23 17:01 rukyr97

After applying the draft patch in #11473 , I managed to build, ctest and install protobuf successfully.

However, when returning to the project where protobuf is used, I am getting the following errors in the building process

Consolidate compiler generated dependencies of target stdlib_pch Consolidate compiler generated dependencies of target stdlib_pch_exec [ 0%] Running python protocol buffer compiler on model/messages.proto /usr/local/bin/protoc-3.21.4.0: error while loading shared libraries: libabsl_city.so.2206.0.0: cannot open shared object file: No such file or directory gmake[2]: *** [contrib/opengym/CMakeFiles/libopengym-obj.dir/build.make:83: ../contrib/opengym/model/ns3gym/ns3gym/messages_pb2.py] Error 127 gmake[1]: *** [CMakeFiles/Makefile2:1251: contrib/opengym/CMakeFiles/libopengym-obj.dir/all] Error 2 gmake[1]: *** Waiting for unfinished jobs....

If it helps the debug process: model/messages.proto source file

rukyr97 avatar Jan 06 '23 19:01 rukyr97

That sounds like you're just missing our Abseil dependency, which we've newly added for 22.x. I'm a little confused by what you're doing though, because your protoc version is 3.21.4, which shouldn't have the Abseil dependency. Could you be mixing 21.x and 22.x (i.e. main)?

mkruskal-google avatar Jan 10 '23 17:01 mkruskal-google

I fixed this by deleting every protobuf version of my system and running the commands below. However I'm still not sure what happened with building the main branch of protobuf

git clone --recurse-submodules --branch v21.12 https://github.com/protocolbuffers/protobuf.git
cd protobuf
mkdir build
cd build
cmake -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF ..
make
make install  

rukyr97 avatar Jan 13 '23 19:01 rukyr97

I suspect what happened is that you were building from main where we have an Abseil dependency, and some of your files from the installed 21.4 were interfering with the build. Removing all your installed versions should fix the issues with main (or 21.12)

mkruskal-google avatar Jan 23 '23 21:01 mkruskal-google