在CMakeList.txt文件中包含OpenSSL [英] Include OpenSSL in a CMakeList.txt file
问题描述
对于在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_package
和find_library
包括在内.设置一些变量,但我找不到办法.
I tried to include with find_package
, find_library
.. setting some variables but I do not find the way.
我的环境是:
- macOS
- Clion
- Podofo通过自制软件安装在
/usr/local/podofo
中
- 通过home-brew在
/usr/local/opt/openssl
中安装的OpenSSL
- macOS
- Clion
- Podofo installed via home-brew in
/usr/local/podofo
- OpenSSL installed via home-brew in
/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屋!