第三方库导致 'undefined reference' 编译器错误?

Third party library causes 'undefined reference' compiler errors?

我是 C++ 的新手。我正在创建一个使用 libcurlpp 访问网页的简单 GUI 应用程序,如下所示:

#include <sstream>
#include <string>

#include <curlpp/cURLpp.hpp>
#include <curlpp/Options.hpp>

using curlpp::Cleanup;
using curlpp::options::Url;

using std::ostringstream;
using std::string;

string MainWindow::getstr(const string &uri)
{
    Cleanup cleanup;

    ostringstream stream;
    stream << Url(uri);

    return stream.str();
}

但是,当我编译代码时,我收到大约 20 个不同的链接器错误,指出对 curlpp 的所有引用都未定义。果然,当我转到包含目录时,我只看到头文件。

如果重要的话,我在 Ubuntu 14.04 上,我通过 运行 和 apt-get install libcurlpp-dev 安装了 libcurlpp。我还需要做些什么来将编译器指向 .cpp/.o 文件并删除未定义的引用吗?


免责声明: 是的,我读过 this,不,它与我的问题无关,因为它没有专门讨论处理第三方 - party 库和实现文件(.cpp.o)在我的系统上的安装位置。

您必须将库添加到链接器。如果你使用的是 Qt Creator,写

LIBS += -lcurlpp

.pro 文件中。

编辑:您必须以这种方式添加所有库。正如评论所说,在 cURL++ 的情况下,它是 cURL C 库的包装器,您还需要 -lcurl.

如果没有libcurlpp.alibcurlpp.so,建议您重新下载libcurlpp-dev,包内有库文件。