简体   繁体   English

如何在Qt创建者项目中使用restclient-cpp?

[英]How can i use restclient-cpp in a Qt creator project?

I'm working on my first QT project. 我正在做我的第一个QT项目。 I need to access a Rest API and decided to give https://github.com/mrtazz/restclient-cpp a try. 我需要访问Rest API并决定尝试https://github.com/mrtazz/restclient-cpp

The issue is that i'm not able to make it work. 问题是我无法使其工作。 I'm getting this error when building the project: 构建项目时出现此错误:

Undefined symbols for architecture x86_64:
  "RestClient::get(std::string const&)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64

I'm not sure if this is correct. 我不确定这是否正确。 But i downloaded restclient-cpp and curl into 3rdparty/libs folder. 但是我下载了restclient-cpp并卷曲到3rdparty / libs文件夹中。

After that, added the following code in my .pro file: 之后,在我的.pro文件中添加以下代码:

LIBS += -L"$$_PRO_FILE_PWD_/3rdparty/libs/"
INCLUDEPATH += "$$_PRO_FILE_PWD_/3rdparty/libs/"

In main.cpp I added: 在main.cpp中,我添加了:

#include <restclient-cpp/include/restclient.h>

And the error happens when i add the following line to my code: 当我在代码中添加以下行时,就会发生错误:

RestClient::response r = RestClient::get("http://localhost/customers");

Without this line, at least I can build the project. 没有这一行,至少我可以构建该项目。

What's the right way to do this? 什么是正确的方法?

Additional information 附加信息

Here is my folder structure: 这是我的文件夹结构:

bash-3.2$ cd 3rdparty/libs/
bash-3.2$ ls -lh
total 0
drwxr-xr-x@ 42 fernando  staff   1,4K 24 Jan 23:30 curl
drwxr-xr-x  34 fernando  staff   1,1K 24 Jan 23:57 restclient-cpp
bash-3.2$ cd restclient-cpp/
bash-3.2$ ls
LICENSE                 README.md               config.guess            config.status           depcomp                 libtool                 stamp-h1
Makefile                aclocal.m4              config.h                config.sub              include                 ltmain.sh               test
Makefile.am             autom4te.cache          config.h.in             configure               install-sh              missing                 utils
Makefile.in             compile                 config.log              configure.ac            librestclient-cpp.la    source                  vendor

I compiled curl and restclient. 我编译了curl和restclient。 Curl was compiled with a basic ./configure && make. Curl使用基本的./configure && make进行编译。 Restclient was compiled with: Restclient使用以下命令进行编译:

autoreconf -vif
./configure
make

Install curl( example ): 安装curl( example ):

  • install libcurl. 安装libcurl。 open terminal and issue the command “sudo apt-get install curl” without the qoutes. 打开终端,然后发出不带qoutes的命令“ sudo apt-get install curl”。
  • the do this in your terminal again: 再次在您的终端上执行此操作:
  • “sudo apt-get install libcurl4-openssl-dev” “ sudo apt-get安装libcurl4-openssl-dev”
  • “sudo apt-get install libcurl4-gnutls-dev” “ sudo apt-get安装libcurl4-gnutls-dev”
  • “sudo apt-get install libcurl4-nss-dev” “ sudo apt-get安装libcurl4-nss-dev”

Insall restclient-cpp: 安装restclient-cpp:

  • ./autogen.sh ./autogen.sh
  • ./configure 。/配置
  • make install 进行安装

My .pro file example: 我的.pro文件示例:

# Add restclient-cpp
LIBS += -L/usr/local/lib/ -lrestclient-cpp

And just add: 并添加:

#include "restclient.h"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM