2017-03-06 42 views
-1

我嘗試寫一些代碼在C++中QtCreator連接到grpc服務器時,我得到這個編譯器錯誤:使用GRPC與QtCreator,未定義的參考`GRPC :: ...`

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

這裏是我的grpc包括在serverproxy.cpp

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

頂部和誤差來源於此行:

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

我試着添加現有的文件,並在QtCreator中添加這些頭文件(儘管手動將頭文件移動到所有外部庫會非常奇怪),但它不起作用。他們位於/usr/local/include/grpc++/**/*.h。 還嘗試將INCLUDEPATH += /usr/local/include添加到我的.pro文件中。

我也嘗試清理項目,運行qmake並再次建設。

我該怎麼做才能使用這些grpc++函數?

回答

0

我看着這麼多undefined reference in qtcreator線程沒有注意到這一點,我終於看到了here這就是擺脫了undefined reference錯誤:

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>

專門

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