7

Why can't linker find absl references?

Configuration:

Raspberry Pi 4 Model B (AArch64) | Ubuntu Server 20.04 | Clang++ (llvm 13.0.0) | GRPC v1.41.1 (libprotoc 3.17.3)

Installed GRPC with these options:

cmake -DgRPC_INSTALL=ON -DCMAKE_BUILD_TYPE=Release -DgRPC_ABSL_PROVIDER=module -DgRPC_CARES_PROVIDER=module -DgRPC_PROTOBUF_PROVIDER=module -DgRPC_RE2_PROVIDER=module -DgRPC_SSL_PROVIDER=module -DgRPC_ZLIB_PROVIDER=module -j4 ../

sudo make install

Command:

clang++ -std=c++17 -iquote /home/ubuntu/gameserver/server/include -include /usr/local/include/grpcpp/support/method_handler.h -L /usr/local/lib src/gameserver.pb.cc src/gameserver.grpc.pb.cc server_test.cpp -lprotobuf -lpthread -ljsoncpp -lgrpc -lgrpc++ -lgrpc++_reflection -labsl_base -labsl_synchronization -labsl_malloc_internal -labsl_stacktrace -labsl_raw_logging_internal -labsl_time -labsl_graphcycles_internal -labsl_spinlock_wait -lgrpc_unsecure -lz -labsl_symbolize -lgpr -labsl_status -labsl_statusor -o server_test -v -Wl,--verbose

Linker finds base class (Found in this [header][1]) :

/usr/local/lib/libabsl_base.a

Error:

/usr/bin/ld: /usr/local/lib/libabsl_synchronization.a(mutex.cc.o): in function 'absl::lts_20210324::EnsureSynchEvent(std::atomic<long>*, char const*, long, long)':
mutex.cc:(.text+0x1f0): undefined reference to 'absl::lts_20210324::base_internal::SpinLock::SlowUnlock(unsigned int)'

Update #1:

Rebuilt/installed grpc and absl using -DCMAKE_CXX_STANDARD=17 just to make sure everything is on the same standard.

Found new error when modifying order of linked libraries...

New Command:

clang++ -iquote /home/ubuntu/gameserver/server/include -include /usr/local/include/grpcpp/support/method_handler.h -L /usr/local/lib src/gameserver.pb.cc src/gameserver.grpc.pb.cc server_test.cpp -o server_test -labsl_status -labsl_strings -lgrpc -lgrpc++ -labsl_synchronization -lgrpc_unsecure -labsl_base -lprotobuf -lpthread -ljsoncpp -lgrpc++_reflection   -labsl_malloc_internal -labsl_stacktrace -labsl_raw_logging_internal -labsl_time -labsl_graphcycles_internal -labsl_spinlock_wait  -lz -labsl_symbolize -lgpr  -labsl_statusor  -std=c++17 -v -Wl,--verbose

New Errors:

/usr/bin/ld: /usr/local/lib/libgrpc_unsecure.a(client_channel.cc.o): in function `grpc_core::ClientChannel::LoadBalancedCall::RecvTrailingMetadataReady(void*, grpc_error*)':
client_channel.cc:(.text+0x774): undefined reference to `absl::lts_20210324::Status::Status(absl::lts_20210324::StatusCode, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: client_channel.cc:(.text+0x8d8): undefined reference to `absl::lts_20210324::Status::Status(absl::lts_20210324::StatusCode, std::basic_string_view<char, std::char_traits<char> >)'
/usr/bin/ld: client_channel.cc:(.text+0x8e8): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: client_channel.cc:(.text+0x918): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: client_channel.cc:(.text+0x930): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: client_channel.cc:(.text+0xa2c): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: client_channel.cc:(.text+0xa38): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: /usr/local/lib/libgrpc_unsecure.a(client_channel.cc.o):client_channel.cc:(.text+0xa54): more undefined references to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)' follow
/usr/bin/ld: /usr/local/lib/libgrpc_unsecure.a(client_channel.cc.o): in function `std::_Function_handler<bool (grpc_core::LoadBalancingPolicy::PickResult::Drop*), grpc_core::ClientChannel::LoadBalancedCall::PickSubchannelLocked(grpc_error**)::{lambda(grpc_core::LoadBalancingPolicy::PickResult::Drop*)#4}>::_M_invoke(std::_Any_data const&, grpc_core::LoadBalancingPolicy::PickResult::Drop*&&)':
client_channel.cc:(.text+0x354c): undefined reference to `absl::lts_20210324::Status::ToStringSlow[abi:cxx11](absl::lts_20210324::StatusToStringMode) const'
/usr/bin/ld: client_channel.cc:(.text+0x3590): undefined reference to `absl::lts_20210324::Status::UnrefNonInlined(unsigned long)'
/usr/bin/ld: /usr/local/lib/libgrpc_unsecure.a(client_channel.cc.o): in function `std::_Function_handler<bool (grpc_core::LoadBalancingPolicy::PickResult::Fail*), grpc_core::ClientChannel::LoadBalancedCall::PickSubchannelLocked(grpc_error**)::{lambda(grpc_core::LoadBalancingPolicy::PickResult::Fail*)#3}>::_M_invoke(std::_Any_data const&, grpc_core::LoadBalancingPolicy::PickResult::Fail*&&)':

Update #2:

Rebuilt/installed absl using -DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0' as mentioned [here][2].

Still same error as update #1.

Engineero
  • 12,340
  • 5
  • 53
  • 75
x84a01
  • 71
  • 1
  • 3
  • Welcome to the site. Please use code blocks to format code and program outputs, see https://stackoverflow.com/help/formatting. Enclose text in `\`...\`` to get it inline, or for multi-line blocks, enclose between `\`\`\``. If you use `*` for italics as you did, it messes up output that contains a `*` character. I have fixed your post for you, but please note this for the future. – Nate Eldredge Nov 06 '21 at 18:31
  • Much appreciated. Will do from now on. – x84a01 Nov 06 '21 at 18:45
  • I believe the entire GRPC library (and submodules) have to be built targeting c++17, not just ABSL. That specific standard changes how std::string is handled. Update1 and 2 may be caused by GRPC not being built against c++17. – Matthew B. Jan 19 '22 at 15:28
  • 1
    Your link is broken. Where you reference "[here][2]", there is no reference for [2], so we just get text and no link. Same in "[header][1]" further up, I just noticed. – Engineero Nov 16 '22 at 00:44

1 Answers1

2

Try rebuilding abseil-cpp with -std=c++17.

From the grpc directory:

mkdir -p third_party/abseil-cpp/cmake/build
pushd third_party/abseil-cpp/cmake/build
cmake -std=c++17 \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ../..
make -j
make install
popd
steepestascent
  • 153
  • 2
  • 7