在 CMakeList.txt 文件中包含 OpenSSL [英] Include OpenSSL in a CMakeList.txt file

查看:51
本文介绍了在 CMakeList.txt 文件中包含 OpenSSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题要问在 C++ 中使用 CMakeList.txt 的人.我想使用 Podofo 项目(一个解析和创建 pdf 的项目).

I have a question for people who work with CMakeList.txt in C++. I want to use Podofo project (a project to parse & create pdf).

所以我的主要功能很简单:

So my main function is simple as:

#include <iostream>
#include <podofo/podofo.h>

int main() {
  PoDoFo::PdfMemDocument pdf;
  pdf.Load("/Users/user/path/to.pdf");

  int nbOfPage = pdf.GetPageCount();

  std::cout << "Our pdf have " << nbOfPage << " pages." << std::endl;
  return 0;
}

我的 CMakeList.txt 是:

My CMakeList.txt is:

cmake_minimum_required(VERSION 3.7)
project(untitled)

set(CMAKE_CXX_STANDARD 14)

set(SOURCE_FILES main.cpp)

add_executable(untitled ${SOURCE_FILES})

但我被这个错误困住了:

But I am stuck with this error:

/usr/local/include/podofo/base/PdfEncrypt.h:44:10: fatal error: 'openssl/opensslconf.h' file not found
#include <openssl/opensslconf.h

我尝试使用 find_packagefind_library 来包含 .. 设置了一些变量,但我没有找到方法.

I tried to include with find_package, find_library .. setting some variables but I do not find the way.

我的环境是:

  • macOS
  • 克里昂
  • Podofo 通过 home-brew 安装在 /usr/local/podofo
  • OpenSSL 通过 home-brew 安装在 /usr/local/opt/openssl

感谢提前社区!!

推荐答案

find_package 是正确的做法;您可以在此处找到有关它的详细信息.

find_package is the correct approach; you find details about it here.

在您的情况下,您应该添加以下几行:

In your case, you should add these lines:

find_package(OpenSSL REQUIRED)
target_link_libraries(untitled OpenSSL::SSL)

如果CMake没有直接找到OpenSSL,你应该设置CMake变量OPENSSL_ROOT_DIR.

If CMake doesn't find OpenSSL directly, you should set the CMake variable OPENSSL_ROOT_DIR.

这篇关于在 CMakeList.txt 文件中包含 OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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