5

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.

Luuk D. Jansen
  • 4,120
  • 7
  • 41
  • 86
  • do you have/did you build the right libs? (64bit) - `Undefined symbols for architecture x86_64` – Caribou Mar 27 '13 at 11:47
  • Probably didn't, install curl using "port", but would assume that is x86_64 for a Mac. Do I have to build it from scratch? – Luuk D. Jansen Mar 27 '13 at 11:53
  • I'm not Mac proficient, I was just highlighting the curlpp error because you said that you were not used to using C++ and sometimes people miss the key bits. The cause might be library paths or names if it is installed correctly. Sorry I can't be more help. – Caribou Mar 27 '13 at 11:59

1 Answers1

12

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)

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

Joel Bodenmann
  • 1,776
  • 2
  • 11
  • 29
Alexandre Ortiz
  • 136
  • 1
  • 3
  • Well, that was easy! Thanks a million, could have saved me a day! – Luuk D. Jansen Mar 27 '13 at 19:17
  • 1
    Hi. on my Mac OS I downloaded curl, entered its main folder and ran ./configure, make and make install. everything seems to have worked properly. now, I need to link curl to my project. I modified CMakeLists as you states, but compiler can't find curl's headers. should I even move some specific files inside curl's folder (where I compiled) in specify positions inside my project? thank you – ubisum Sep 30 '16 at 17:44