0

I'm a newcomer to C++. I am creating a simple GUI application that uses libcurlpp to visit a webpage, like so:

#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();
}

However, when I compile the code, I get about 20 different linker errors saying that all the references to curlpp are undefined. Sure enough, when I go to the include directories, I see only header files.

If it matters, I'm on Ubuntu 14.04 and I installed libcurlpp by running an apt-get install libcurlpp-dev. Is there anything else I have to do to point the compiler to the .cpp/.o files and get rid of the undefined references?


Disclaimer: Yes, I did read this, and no, it isn't relevant to my question because it does not talk specifically about dealing with third-party libraries and where the implementation files (.cpp and .o) are installed on my system.

Community
  • 1
  • 1
James Ko
  • 32,215
  • 30
  • 128
  • 239
  • Out of curiosity, is there a `libcurlpp.so` or `libcurlpp.a` hiding somewhere in the general proximity of your /usr/local/lib folder (or subdirectory therein) ? Show your final *build* line that fails to link your program so we can all see how `-lcurlpp` hasn't been mistakenly left out. Otherwise, that linked question is *very* relevant. – WhozCraig Jul 24 '15 at 05:56
  • @WhozCraig No, I just checked `/usr/lib` and `/usr/local/lib` and no `curlpp` libraries. I added a `QMAKE_CXXFLAGS += -lcurlpp` in my `.pro` file (since I'm using Qt + qmake) to [pass arguments to the compiler](http://stackoverflow.com/questions/7980499/where-in-qt-creator-do-i-pass-arguments-to-a-compiler), but it still shows me the same error. – James Ko Jul 24 '15 at 06:02

2 Answers2

3

If there is no any libcurlpp.a or libcurlpp.so , then i recommend you to download again libcurlpp-dev , there are library files inside package.

udit043
  • 1,610
  • 3
  • 22
  • 40
2

You have to add the library to the linker. If you are using Qt Creator, write

LIBS += -lcurlpp

in the .pro file.

EDIT: You have to add all libraries this way. As the comment says, in the case of cURL++, which is a wrapper for the cURL C library, you'll also need -lcurl.

vukung
  • 1,824
  • 10
  • 23
  • This eliminated most of the errors for me, but I still had some issues linking until I added `libcurl` as well (`LIBS += -lcurl -lcurlpp`). Please update your answer to reflect this (thanks!). – James Ko Jul 24 '15 at 15:25