Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

c++ - Include OpenSSL in a CMakeList.txt file

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;
}

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

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

My env is:

  • macOS
  • Clion
  • Podofo installed via home-brew in /usr/local/podofo
  • OpenSSL installed via home-brew in /usr/local/opt/openssl

Thanks by advance community !!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...