为什么链接器找不到absl引用?

问题描述 投票:0回答:2

为什么链接器找不到absl引用?

配置:

Raspberry Pi 4 B 型(AArch64)| Ubuntu 服务器 20.04 | Clang++ (llvm 13.0.0) | GRPC v1.41.1(libprotoc 3.17.3)

使用以下选项安装 GRPC:

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

命令:

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

链接器找到基类(在此[标题][1]中找到):

/usr/local/lib/libabsl_base.a

错误:

/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)'

更新#1:

使用

grpc
重建/安装
absl
-DCMAKE_CXX_STANDARD=17
只是为了确保一切都符合相同的标准。

修改链接库顺序时发现新错误...

新命令:

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

新错误:

/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*&&)':

更新#2:

按照[此处][2]所述使用

absl
重建/安装
-DCMAKE_CXX_FLAGS='-D_GLIBCXX_USE_CXX11_ABI=0'

仍然出现与更新 #1 相同的错误。

c++ grpc ubuntu-server abseil
2个回答
2
投票

尝试使用

-std=c++17
重建 Abseil-cpp。

来自 grpc 目录:

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

0
投票

与很多人一样的问题,无论是在 Ubuntu 18.04 还是 ubuntu 23.10 中。我找到了一个不错的替代方案来考虑,我使用 MQTT 代替 GRPC。 protobuf 消息是相同的。然后消息仍然相同,您可以使用相同的 .proto 文件。

仅传输协议不同。 mqtt 的一大优点是,如果需要,您可以向许多客户端广播。网上有足够多的 C++、Python 和 Kotlin 示例。对我来说,我使用 paho-mqtt。

© www.soinside.com 2019 - 2024. All rights reserved.