未定义的参考GRPC和Protobuf错误-C++

发布于 2025-02-03 12:24:14 字数 2801 浏览 1 评论 0原文

我正在在两个实体(Matchmaker and Host)之间编写GRPC通信代码。我的makefile看起来如下:

CXX = g++
LDFLAGS +=  `pkg-config --cflags --libs protobuf grpc grpc++`\
           -lgrpc++_reflection\
           -ldl


host: comm hosts/host.cc hosts/host.h
    $(CXX) $(LDFLAGS) hosts/host.cc build/matchmaker.grpc.pb.o build/matchmaker.pb.o -g -o build/host.o

comm: comm/matchmaker.grpc.pb.cc comm/matchmaker.grpc.pb.h comm/matchmaker.pb.cc comm/matchmaker.pb.h
    $(CXX) $(LDFLAGS) comm/matchmaker.grpc.pb.cc -g -c -o build/matchmaker.grpc.pb.o
    $(CXX) $(LDFLAGS) comm/matchmaker.pb.cc -g -c -o build/matchmaker.pb.o

我正在为GRPC和ProtoBuf类代码遇到多个未定义的参考错误。错误的某些部分如下:

/usr/bin/ld: /tmp/cciFPkpo.o: in function `Host::RegisterHost()':
~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::ClientContext()'
/usr/bin/ld: ~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::~ClientContext()'
/usr/bin/ld: ~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::~ClientContext()'
/usr/bin/ld: /tmp/cciFPkpo.o: in function `main':
~/Projects/p1/hosts/host.cc:27: undefined reference to `grpc::InsecureChannelCredentials()'
.
.
.

~/Projects/p1/hosts/../comm/matchmaker.pb.h:895: undefined reference to `google::protobuf::RepeatedField<float>::Set(int, float const&)'

pkg-config的输出 - flags-libs protobuf grpc grpc grpc ++如下:

-DNOMINMAX -maes -msse4.1 -DNOMINMAX -maes -msse4.1 -DNOMINMAX -I~/grpc/include -L~/grpc/lib -lprotobuf -pthread -lgrpc++ -lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -lgpr -lssl -lcrypto -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_hash -labsl_city -labsl_low_level_hash -labsl_random_distributions -labsl_random_seed_sequences -labsl_random_internal_pool_urbg -labsl_random_internal_randen -labsl_random_internal_randen_hwaes -labsl_random_internal_randen_hwaes_impl -labsl_random_internal_randen_slow -labsl_random_internal_platform -labsl_random_internal_seed_material -labsl_random_seed_gen_exception -labsl_statusor -labsl_status -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_exponential_biased -labsl_cordz_handle -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_stacktrace -labsl_symbolize -labsl_debugging_internal -labsl_demangle_internal -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_strings -labsl_strings_internal -lrt -labsl_base -labsl_spinlock_wait -labsl_int128 -labsl_throw_delegate -labsl_time_zone -labsl_bad_variant_access -labsl_raw_logging_internal -labsl_log_severity

GRPC和ProtoBuf先前是通过软件中心安装的,我删除了该软件中心。当前的GRPC和Protobuf是根据源代码构建的。

我不确定如何解决未定义的参考错误。任何指针都会非常有帮助。提前致谢。

I am writing a grpc communication code between two entities, matchmaker and host. My makefile looks as below:

CXX = g++
LDFLAGS +=  `pkg-config --cflags --libs protobuf grpc grpc++`\
           -lgrpc++_reflection\
           -ldl


host: comm hosts/host.cc hosts/host.h
    $(CXX) $(LDFLAGS) hosts/host.cc build/matchmaker.grpc.pb.o build/matchmaker.pb.o -g -o build/host.o

comm: comm/matchmaker.grpc.pb.cc comm/matchmaker.grpc.pb.h comm/matchmaker.pb.cc comm/matchmaker.pb.h
    $(CXX) $(LDFLAGS) comm/matchmaker.grpc.pb.cc -g -c -o build/matchmaker.grpc.pb.o
    $(CXX) $(LDFLAGS) comm/matchmaker.pb.cc -g -c -o build/matchmaker.pb.o

I am getting multiple undefined reference errors for grpc and protobuf class codes. Some part of the error is shown below:

/usr/bin/ld: /tmp/cciFPkpo.o: in function `Host::RegisterHost()':
~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::ClientContext()'
/usr/bin/ld: ~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::~ClientContext()'
/usr/bin/ld: ~/Projects/p1/hosts/host.cc:11: undefined reference to `grpc::ClientContext::~ClientContext()'
/usr/bin/ld: /tmp/cciFPkpo.o: in function `main':
~/Projects/p1/hosts/host.cc:27: undefined reference to `grpc::InsecureChannelCredentials()'
.
.
.

~/Projects/p1/hosts/../comm/matchmaker.pb.h:895: undefined reference to `google::protobuf::RepeatedField<float>::Set(int, float const&)'

The output for pkg-config --cflags --libs protobuf grpc grpc++ is as below:

-DNOMINMAX -maes -msse4.1 -DNOMINMAX -maes -msse4.1 -DNOMINMAX -I~/grpc/include -L~/grpc/lib -lprotobuf -pthread -lgrpc++ -lgrpc -laddress_sorting -lre2 -lupb -lcares -lz -lgpr -lssl -lcrypto -labsl_raw_hash_set -labsl_hashtablez_sampler -labsl_hash -labsl_city -labsl_low_level_hash -labsl_random_distributions -labsl_random_seed_sequences -labsl_random_internal_pool_urbg -labsl_random_internal_randen -labsl_random_internal_randen_hwaes -labsl_random_internal_randen_hwaes_impl -labsl_random_internal_randen_slow -labsl_random_internal_platform -labsl_random_internal_seed_material -labsl_random_seed_gen_exception -labsl_statusor -labsl_status -labsl_cord -labsl_cordz_info -labsl_cord_internal -labsl_cordz_functions -labsl_exponential_biased -labsl_cordz_handle -labsl_bad_optional_access -labsl_str_format_internal -labsl_synchronization -labsl_graphcycles_internal -labsl_stacktrace -labsl_symbolize -labsl_debugging_internal -labsl_demangle_internal -labsl_malloc_internal -labsl_time -labsl_civil_time -labsl_strings -labsl_strings_internal -lrt -labsl_base -labsl_spinlock_wait -labsl_int128 -labsl_throw_delegate -labsl_time_zone -labsl_bad_variant_access -labsl_raw_logging_internal -labsl_log_severity

grpc and protobuf was previous installed via software center, which I removed. The current grpc and protobuf is built from the source code.

I am not sure how to resolve the undefined reference error. Any pointers will be really helpful. Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稚气少女 2025-02-10 12:24:14

您需要将$(ldflags)移动到之后 依赖它的对象文件:

host: comm hosts/host.cc hosts/host.h
    $(CXX) hosts/host.cc build/matchmaker.grpc.pb.o build/matchmaker.pb.o -g -o build/host $(LDFLAGS) 

You need to move the $(LDFLAGS) until after the object files that depend on it:

host: comm hosts/host.cc hosts/host.h
    $(CXX) hosts/host.cc build/matchmaker.grpc.pb.o build/matchmaker.pb.o -g -o build/host $(LDFLAGS) 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文