如何在QT创建项目中使用RESTCLIENT-CPP

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

本文关键字:RESTCLIENT-CPP 项目 创建 QT      更新时间:2023-10-16

我正在研究我的第一个QT项目。我需要访问REST API,并决定给予https://github.com/mrtazz/restclient-cpp a尝试。

问题是我无法使它起作用。构建项目时,我会遇到此错误:

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

我不确定这是否正确。但是我下载了RestClient-CPP并卷曲到3rdparty/libs文件夹中。

之后,在我的.pro文件中添加了以下代码:

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

在main.cpp中添加:

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

,当我将以下行添加到我的代码中时发生错误:

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

没有这条线,至少我可以构建项目。

正确的方法是什么?

其他信息

这是我的文件夹结构:

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

我编译了卷曲和静止。Curl用基本的./configure&amp;&amp;制作。restclient编译了:

autoreconf -vif
./configure
make

安装curl(示例):

  • 安装libcurl。开放终端并发出命令" sudo apt-get install curl",而无需Qoutes。
  • 再次在您的终端中执行此操作:
  • " sudo apt-get安装libcurl4-openssl-dev"
  • " sudo apt-get安装libcurl4-gnutls-dev"
  • " sudo apt-get安装libcurl4-nss-dev"

insall restclient-cpp:

  • ./autogen.sh
  • ./配置
  • 使安装

我的.pro文件示例:

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

,然后添加:

#include "restclient.h"