GRPC helloworld server "undefined references"
-
Hello everyone !
I want to design a gRPC server on Qt. So, I took the helloword program on grpc website and I linked it with Qt.
But this code exeample didn't work :I use :
Os : Debian 9
Qt : 5.13.2
Protoc : 3.19.4My pro file :
QT -= gui #QT += protobuf grpc core CONFIG += c++11 console CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 INCLUDEPATH += \ /home/name/.local/include/ \ /home/name/.local/lib/ \ LIBS += -L/usr/local/lib `pkg-config --libs protobuf grpc++` -pthread -lgrpc++_reflection -ldl SOURCES += \ greeter_server.cc \ helloworld.grpc.pb.cc \ helloworld.pb.cc HEADERS += \ helloworld.grpc.pb.h \ helloworld.pb.h DISTFILES += \ helloworld.proto
I have no idea how to solve this issue.
I really thank you in advance for your help ! -
@NikoBir said in GRPC helloworld server "undefined references":
pkg-config --libs protobuf grpc++
The output shows missing external references to
grpc
functions. Have you checked just what thepkg-config
command above returns for use into theLIBS
variable? Is that syntactically correct, and is it enough together with-lgrpc++_reflection
everything needed? Have a look at the completeg++
link line as it is generated and issued fro Creator. -
Hi,
Your LIBS looks wrong on several levels. It's missing backslashes since you made it multiline and I do not remember that syntax for retrieving something.
qmake has support for pkg-config so you should rather use that.
-
Thanks both of you for your indication !
Indeed, it was the pkg-config (that didn't return the grpc.pc file) and my libs in LIBS.
So, I deleted the useless libs and I add in the PKG_CONFIG_PATH, the path to the grpc.pc lib.Now, my pro file is :
QT -= gui #QT += protobuf grpc core CONFIG += c++11 console CONFIG -= app_bundle # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 INCLUDEPATH += \ /home/name/.local/include/ \ /home/name/.local/lib/ \ LIBS += -L/usr/local/lib `pkg-config --libs grpc++` SOURCES += \ greeter_server.cc \ helloworld.grpc.pb.cc \ helloworld.pb.cc HEADERS += \ helloworld.grpc.pb.h \ helloworld.pb.h DISTFILES += \ helloworld.proto
After correcting this issue, I have this error on the output terminal :
error while loading shared libraries: libgrpc++.so.1.45: cannot open shared object file: No such file or directory
So, after some research, I followed this advice :
but it was ineffective....
I tested to add in the pro file :
QMAKE_LFLAGS += -Wl,-rpath,"path_to_ibgrpc++.so.1.45"
Do you know how to resolve this issue ?
-
Where is that library located in your machine ?
As an alternative, you can set the LD_LIBRARY_PATH environment variable and add that folder to it.
-
@SGaist said in GRPC helloworld server "undefined references":
LD_LIBRARY_PATH
Thanks for your answer !
The library is located in "/home/name/.local/lib/libgrpc++.so.1.45".
I tested your advice, I addes the directory path in my bashrc :
export LD_LIBRARY_PATH="/home/edf/.local/lib/"And I updated it.
But, I have the same issue :/
-
Are you sure your project picked it up ?
Check the Run part of the project panel.