Why can't linker find absl references?
Asked Answered
O

2

9

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.

Orelia answered 6/11, 2021 at 18:3 Comment(6)
Welcome to the site. Please use code blocks to format code and program outputs, see 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.Dall
Much appreciated. Will do from now on.Orelia
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.Praiseworthy
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.Hydranth
@Hydranth sir did you manage to solve that error somehow ? Any information or update ?Strickle
@Strickle nope. They just didn't finish the link and never returned to do it.Hydranth
A
0

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
Allieallied answered 28/12, 2021 at 16:21 Comment(2)
cmake -std=c++17 \ will not work. Try like cmake -DCMAKE_CXX_FLAGS=-std=c++17 \Sabotage
Thies does not work. No chance even after recompining.Strickle
A
-1

After puzzling another I found the real problem: I had protoc and protobuf already installed in Linux before I compiled GRPC. In that case GRPC decides that PROTOBUF does not need to compile again. But the change is big that the program tries to link wrong versions of libGRPC and libprotobuf. Best is to uninstall all protobuf versions, then remove remainders of protoc, libproto* and then compile GRPC again.

If this doesn't work, consider to use MQTT with Protobuf instead of GRPC with Protobuf. Changes in your program will be minimum since the messages can be re-used, you can use even the same .proto files.

Arrowy answered 25/1 at 21:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.