使用CMake链接项目中的curl [英] Linking curl in a project using CMake

查看:1344
本文介绍了使用CMake链接项目中的curl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有C ++的经验,只需要对C ++应用程序进行一点调整就可以进行HTTP请求以验证用户身份.

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是一个选项,但是当包含库时,在构建时会出现错误:

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)

据我了解,我需要在CMAKELists.txt文件中添加/链接该库.有人可以告诉我我到底需要添加什么吗? (运行OSX 10.8)正如我提到的,我没有使用C ++的经验,因为我大多数时候都使用Java.

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.

推荐答案

据我了解,我需要在CMAKELists.txt文件中添加/链接该库.

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

这正是您要做的:)

在C ++中,将库包含到项目中时,有两种文件可以使用:

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.

如果要构建名为MyExecutable的可执行文件,则必须有类似

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

add_executable(MyExecutable ...)

在您的CMakeLists.txt中.

在此行之后,尝试添加

target_link_libraries(MyExecutable curlpp)

我已经为MyExecutable目标添加了target_link_libraries()行,只需将curlpp添加到其他库中即可.

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

这篇关于使用CMake链接项目中的curl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆