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

时间:2014-01-24 23:26:45

标签: c++ qt qt-creator

我正在开展我的第一个QT项目。我需要访问Rest API并决定尝试https://github.com/mrtazz/restclient-cpp

问题在于我无法使其发挥作用。我在构建项目时遇到了这个错误:

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和curl下载到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和restclient。 Curl是用一个基本的./configure&amp;&amp;编译的。使。 Restclient编译为:

autoreconf -vif
./configure
make

1 个答案:

答案 0 :(得分:0)

安装curl(example):

  • 安装libcurl。打开终端并发出命令“sudo apt-get install curl”,不带qoutes。
  • 再次在您的终端中执行此操作:
  • “sudo apt-get install libcurl4-openssl-dev”
  • “sudo apt-get install libcurl4-gnutls-dev”
  • “sudo apt-get install libcurl4-nss-dev”

Insall restclient-cpp:

  • ./ autogen.sh
  • ./配置
  • make install

我的.pro文件示例:

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

只需添加:

#include "restclient.h"