未定义的参考GRPC和Protobuf错误-C++
我正在在两个实体(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将
$(ldflags)
移动到之后 依赖它的对象文件:You need to move the
$(LDFLAGS)
until after the object files that depend on it: