Matthias
Matthias

Reputation: 3870

Using grpc with QtCreator, undefined reference to `grpc::...`

I am trying to write some code in C++ in QtCreator to connect to a grpc server when I get this compiler error:

/some/path/serverproxy.cpp:40: error: undefined reference to `grpc::InsecureChannelCredentials()'

Here's my grpc includes at the top of serverproxy.cpp

#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
#include <grpc++/security/credentials.h>

and the error comes from this line:

somenamespace::NewStub(
        grpc::CreateChannel("someaddress",
                            grpc::InsecureChannelCredentials()))};

I tried adding existing files and adding these headers in QtCreator (although it would be very strange to have to do that manually for the headers to all external libraries), but it didn't work. They are located at /usr/local/include/grpc++/**/*.h. Also tried adding INCLUDEPATH += /usr/local/include to my .pro file.

I also tried cleaning the project, running qmake and building again.

What do I have to do to be able to use these grpc++ functions?

Upvotes: 1

Views: 6013

Answers (1)

Matthias
Matthias

Reputation: 3870

I looked at so many undefined reference in qtcreator threads without noticing this, which I finally saw here which is what got rid of the undefined reference errors:

You are facing a link error. Just add in your .pro the path to your lib and its name with :

LIBS += -L<path_to_the_lib> -l<libName>

specifically

LIBS += -L/usr/local/include/grpc++ -lgrpc++

Upvotes: 3

Related Questions