c++curlcmakecurlpp

Linking curl in a project using CMake


I don't have experience with C++, and only need to make a small adjustment to a C++ application to do a HTTP request to authenticate a user.

Curlpp is an option, but when including the libraries I get an error on building:

Undefined symbols for architecture x86_64:
  "curlpp::OptionBase::OptionBase(CURLoption)", referenced from:
      app_idomsconnector::RTMPAppProtocolHandler::GetAuthPassword(std::string) in libidomsconnector.a(rtmpappprotocolhandler.cpp.o)
      curlpp::OptionTrait<std::string, (CURLoption)10002>::clone() const in libidomsconnector.a(rtmpappprotocolhandler.cpp.o)

As I understand I need to add/link the library in the CMAKELists.txt file. Can anybody tell me what exactly I need to add? (running OSX 10.8) As I mentioned, I have no experience with C++, as I use Java most of the time.


Solution

  • As I understand I need to add/link the library in the CMAKELists.txt file.

    It is exactly what you have to do :)

    In C++, you have two kinds of files to use when you include a library to your project:

    (this is a little bit simplified but it is not important here)

    The error message tells you that you do not provide the object files to the compiler, so it does not know what some words (classes and functions) you use in your project mean.

    If you are building an executable named MyExecutable, you must have a line like

    add_executable(MyExecutable ...)
    

    in your CMakeLists.txt.

    AFTER this line, try to add

    target_link_libraries(MyExecutable curlpp)
    

    If you already have a target_link_libraries() line for the MyExecutable target, just add curlpp to the others libraries.