0

I am using the poppler-cpp library in my project.

It build & start it correctly, but I need to have popple installed in my system.

What is the way to import (include) the poppler library in my project, the aim is to execute it on another linux system which has not poppler lib installed, is it possible ?

My current cmakeList.txt file:

cmake_minimum_required(VERSION 3.5)
project(poppler_test)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/extra-cmake-modules/find-modules")
find_package(Poppler REQUIRED)
include(CMakeToolsHelpers OPTIONAL)
include_directories(${Poppler_INCLUDE_DIRS})
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)

ADD_LIBRARY(poppler STATIC IMPORTED)

add_dependencies( poppler poppler_test )

add_executable(poppler_test ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${Poppler_LIBRARIES})

My main.cpp Programm

#include <algorithm>
#include <cpp/poppler-document.h>
#include <cpp/poppler-page.h>
#include <exception>
#include <iostream>
#include <memory>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  auto input = "/Home/Dev/poppler-test/test.pdf";
  shared_ptr<poppler::document> doc{poppler::document::load_from_file(input)};
  const int pagesNbr = doc->pages();
  cout << "page count: " << pagesNbr << endl;
  vector<string> infoKeys{doc->info_keys()};
  for_each(infoKeys.begin(), infoKeys.end(),
           [doc](string infoKey) { cout << doc->info_key(infoKey).to_latin1() << endl; });

  for (int i = 0; i < pagesNbr; ++i) {
    shared_ptr<poppler::page> currentPage{doc->create_page(i)};
    if (currentPage == nullptr) {
      auto byteArrayResult = currentPage->text().to_utf8();
      string result{byteArrayResult.begin(), byteArrayResult.end()};
      cout << result << endl;
    }
  }
}
nodeover
  • 301
  • 1
  • 2
  • 11
  • `the aim is to execute it on another linux system which has not poppler lib installed` - So you need either to build the library **statically**, or to ship your program with the library `.so` files. If you choose the first way, for build the library statically pass option `-DBUILD_SHARED_LIBS=OFF` to `cmake`. – Tsyvarev Sep 08 '17 at 19:47
  • I added DBUILD_SHARED_LIBS=OFF but it does not include the library so that it could work in standalone . In fact I would like to do as this post , but there is no answer :ss https://stackoverflow.com/questions/7101862/want-to-make-standalone-program-with-cmake – nodeover Sep 09 '17 at 11:05
  • You should build `poppler-cpp` with that option, not your project. After you build `poppler-cpp` statically and install it, you will get `.a` library instead of `.so` one. Then you may build your own project. – Tsyvarev Sep 09 '17 at 12:15
  • I tried to put a deps/poppler in my project & add it as a subdirectory but now make does not found file required by poppler in its cmakelist.txt. I am not really sure if this cpp lib can be build as a standalone program... – nodeover Sep 10 '17 at 11:14
  • I have poppler-cpp installer on my system & in /usr/local/poppler/ In the lib folder I have .so files & .a !! Is it possible to tell make to get them instead of .so ? – nodeover Sep 10 '17 at 11:24
  • So you need `find_package()` to prefer static libraries over shared ones. See e.g. [this answer](https://stackoverflow.com/a/4126492/3440745). – Tsyvarev Sep 10 '17 at 14:16

0 Answers0