Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22264

Protobuf linking error, undefined reference due to symbol suffix 'B5cxx11'

$
0
0

I'm compiling source files test.cpp(include proto.pb.h) and proto.pb.cc together to a binary file.

I download a library libProtobufLite.a, and compile with command: g++ test.cpp proto.pb.cc -Iinclude -L. -lProtobufLite --std=c++11.

But I got an error: proto.pb.cc undefined reference to `google::protobuf::internal::kEmptyString'

nm libProtobufLite.a | grep "EmptyString" shows that symbol name in library is_ZN6google8protobuf8internal12kEmptyStringB5cxx11Ewhile the symbol in proto.pb.o is_ZN6google8protobuf8internal12kEmptyStringE

my gcc version is

Using built-in specs.COLLECT_GCC=/usr/local/bin/g++COLLECT_LTO_WRAPPER=/usr/local/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.5.0/lto-wrapperTarget: x86_64-pc-linux-gnuConfigured with: ../gcc-7.5.0/configure --prefix=/root/init_server/install --with-dwarf-2 --disable-libstdcxx-dual-abiThread model: posixgcc version 7.5.0 (GCC)

I try to add -D_GLIBCXX_USE_CXX11_ABI=1 to comiling command, but it doesn't work.

How to compile my source files and link to that library?

--- update ---

I tried a new gcc toolchain, /opt/rh/devtoolset-7/root/usr/bin/g++, but I got the same problem (with -D_GLIBCXX_USE_CXX11_ABI=1 in compiling command).

Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linuxThread model: posixgcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)

--- update ---

After upgrading gcc to gcc 8.5.0, this problem solved.

I experimented with three scenarios. I'm curious why Case2 fails

  1. Case 1. gcc 7.5.0 with configure--disable-libstdcxx-dual-abi and compiling option -D_GLIBCXX_USE_CXX11_ABI=1 : failed
  2. Case 2. gcc 7.3.1 with configure--with-default-libstdcxx-abi=gcc4-compatible and compiling option -D_GLIBCXX_USE_CXX11_ABI=1: also failed
  3. Case 3. gcc 8.5.0 without any abi configure or compiling option: succeed

Viewing all articles
Browse latest Browse all 22264


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>