1

I want to add curlpp to my C++ project. Currently, I have a main.cpp file which looks like this:

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

int main() {
  return 0; 
}

I compile using: "g++ -std=c++14 -I/usr/nguyenthesang/Desktop/myprogram/curlpp-0.8.1/include main.cpp" and it successfully compiles.

Then I add the implementation in the main function (the below is copied from curlpp's repo):

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


using namespace curlpp::options;

int main(int, char **)
{
    try
    {
    // That's all that is needed to do cleanup of used resources (RAII 
    style).
    curlpp::Cleanup myCleanup;

    // Our request to be sent.
    curlpp::Easy myRequest;

    // Set the URL.
    myRequest.setOpt<Url>("http://example.com");

    // Send request and get a result.
    // By default the result goes to standard output.
    myRequest.perform();
}

catch(curlpp::RuntimeError & e)
{
    std::cout << e.what() << std::endl;
}

catch(curlpp::LogicError & e)
{
    std::cout << e.what() << std::endl;
}

return 0;
}

When I compile by using "g++ -std=c++14 -I/usr/nguyenthesang/Desktop/myprogram/curlpp-0.8.1/include main.cpp" , there are compilation errors, which say that "ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)".

The errors may come from the fact that I have only linked the header files to the program but not the library itself. I google around to find the way to link the library (for example using -L options) but it did not work. I need help with this problem.

I also want to ask that is there a general way for adding every library into C++ project, like Cocoapods in iOS?

I appreciate your help.

muoi tom
  • 41
  • 2
  • 9

1 Answers1

2

On ubuntu I had success with installing these packages:

sudo apt-get install pkg-config libcurlpp-dev libcurl4-openssl-dev

(pkg-config is to be used in CMakeLists.txt to find the curlpp and set an env var that points to it)
Then in my CMakeLists.txt I added:

include(FindPkgConfig)
pkg_check_modules(CURLPP REQUIRED curlpp)

Then still in CMakeLists.txt add to target_link_libraries ${CURLPP_LDFLAGS} for example:

target_link_libraries(mylibcurlppprog ${CURLPP_LDFLAGS})
kroiz
  • 1,722
  • 1
  • 27
  • 43