15

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 !!

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
nodeover
  • 301
  • 1
  • 2
  • 11

1 Answers1

29

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.

oLen
  • 5,177
  • 1
  • 32
  • 48
  • 1
    Yeah that's it !!! Could you just explain me how did you found the syntax "OpenSSL:SSL", why not just "OpenSSL", I would never found that . Now I have another error "ld: symbol(s) not found for architecture x86_64" but it's certainly a small mistakes – nodeover Aug 07 '17 at 14:27
  • 1
    @nodeover did you look at the FindOpenSSL documentation that was given? These imported target names should always be in there or in the comments of the corresponding FindModule.cmake file. Also, if oLen solved this specific question for you, make sure to mark it as the answer and upvote it. – utopia Aug 07 '17 at 16:15
  • Oh so my second problem was because I missed "target_link_libraries(untitled podofo)" that line resolve the problem & I am able to build – nodeover Aug 08 '17 at 07:28
  • @oLen Why not give `include_directores` or `target_include_directories` of openssl ? – Lewis Chan Oct 21 '18 at 04:17
  • @LewisChan It is not necessary, with this syntax `target_link_libraries` does it for you. – oLen Oct 21 '18 at 07:53