我正在处理我的第一个 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 && make 编译的。 Restclient 编译为:
autoreconf -vif
./configure
make
最佳答案
安装 curl (example):
- 安装 libcurl。打开终端并发出不带 qoutes 的命令“sudo apt-get install curl”。
- 在您的终端中再次执行此操作:
- “sudo apt-get install libcurl4-openssl-dev”
- “sudo apt-get install libcurl4-gnutls-dev”
- “sudo apt-get install libcurl4-nss-dev”
安装restclient-cpp:
- ./autogen.sh
- ./配置
- 安装
我的 .pro 文件示例:
# Add restclient-cpp
LIBS += -L/usr/local/lib/ -lrestclient-cpp
然后添加:
#include "restclient.h"
关于c++ - 我如何在 Qt Creator 项目中使用 restclient-cpp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21344345/