0

On Mac OSX, I installed protobuf from source via gnu g++ successfully. And then, I built a .so library which uses protobuf without any error message. But the problem is when I'm trying to use this .so lib, error occurs saying

Symbol not found: __ZN6google8protobuf8internal26fixed_address_empty_stringB5cxx11E
  Referenced from: a.so
  Expected in: flat namespace

Then I checked if this symbol exists in libprotobuf.a,

>>> nm -g /usr/local/lib/libprotobuf.a | grep fixed_address_empty_string
no symbols
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
00000000000fb600 S __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
no symbols
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE
                 U __ZN6google8protobuf8internal26fixed_address_empty_stringE

strangly there is no fixed_address_empty_stringB5cxx11E, but only fixed_address_empty_stringE.

Please help me to understand how to resolve the problem?

avocado
  • 2,615
  • 3
  • 24
  • 43
  • Are you compiling in C++11 mode? It looks like you were bitten by the ABI change. – Botje Oct 12 '20 at 09:58
  • Does this answer your question? [Undefined reference error despite of having the library specified in CMake](https://stackoverflow.com/questions/64010727/undefined-reference-error-despite-of-having-the-library-specified-in-cmake) – Botje Oct 12 '20 at 09:59
  • @Botje The protobuf is installed with default flags, I think it's `-std=c++11`. And but own `.so` is built with `c++17`. Does it go against with each other? – avocado Oct 12 '20 at 09:59
  • 1
    From the evidence here it looks like that protobuf .a file was not compiled with the CXX11 abi. – Botje Oct 12 '20 at 10:01
  • @Botje, so I should re-compile and install the protobuf lib by explicitly enable `c++11` ABI? – avocado Oct 12 '20 at 10:22
  • Not sure how to comple protobuf .a file with CXX11 abi, just tried by setting `./configure CXXFLAGS="-O3 -std=c++17 -DNDEBUG -D_GLIBCXX_USE_CXX11_ABI=1"`, but the installed .a still has no `fixed_address_empty_stringB5cxx11E`. – avocado Oct 12 '20 at 10:37
  • What version of g++ are you using? What compiler are you compiling protobuf with? – Botje Oct 12 '20 at 11:03
  • @Botje g++10, same compiler compiling protobuf. And from the Makefile after `./configure`, I can see these are set: ```262 CXX = g++ 263 CXXCPP = g++ -E 264 CXXCPPFLAGS_FOR_BUILD = 265 CXXCPP_FOR_BUILD = g++ -E 266 CXXDEPMODE = depmode=gcc3 267 CXXFLAGS = -g -std=c++11 -DNDEBUG 268 CXXFLAGS_FOR_BUILD = -g -O2 269 CXX_FOR_BUILD = g++``` – avocado Oct 12 '20 at 12:32
  • 1
    @Botje Please ignore, I think there was some inconsistency in my env, the `g++` is an alias linked to the gnu-g++10, but I guess `./configure CXX=g++` didn't use the linked one. So again I ran `./configure CC=/usr/local/Cellar/gcc/10.2.0/bin/gcc-10 CXX=/usr/local/Cellar/gcc/10.2.0/bin/g++-10`, and now the installed protobuf .a file has cxx11 abi. – avocado Oct 12 '20 at 12:48

0 Answers0