Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 725
Luuk D. Jansen Avatar asked Mar 27 '13 11:03

Luuk D. Jansen


People also ask

Does CMake include GCC?

a. This "cmake and make" stuffs actually use g++ / gcc in its implementation.

Can you use CMake in Visual Studio?

Visual Studio's native support for CMake enables you to edit, build, and debug CMake projects on Windows, the Windows Subsystem for Linux (WSL), and remote systems from the same instance of Visual Studio. CMake project files (such as CMakeLists.

Can you use CMake with C?

In the C/C++ ecosystem, the best tool for project configuration is CMake. CMake allows you to specify the build of a project, in files named CMakeLists. txt, with a simple syntax (much simpler than writing Makefiles).


1 Answers

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:

  • header files, where the names of symbols are declared (like a list of words)
  • object files, where the code stands (like a dictionary where the words are actually defined)

(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.

like image 51
Alexandre Ortiz Avatar answered Oct 04 '22 20:10

Alexandre Ortiz