With @Botje's suggestion in the comments, I installed poppler via apt
tool in my Ubuntu 24.04.
Also I compiled my main.cpp using the following command -
g++ main.cpp -o main $(pkg-config --cflags --libs poppler-cpp)
It compiled without any warning or error message, but when I run it, the ./main
program threw this error -
./main: error while loading shared libraries: libpoppler-cpp.so.2: cannot open shared object file: No such file or directory
I also tried the compilation with this command -
g++ main.cpp -o main $(pkg-config --cflags --libs poppler poppler-cpp)
but still same error.
My doubt here is, how did the g++ decide that it should link my program with libpoppler-cpp.so.2
, when there is no such file in the /usr/lib/x86_64-linux-gnu
directory? The following are the only poppler-related files in that directory:
/usr/lib/x86_64-linux-gnu/libpoppler.so
/usr/lib/x86_64-linux-gnu/libpoppler.so.134
/usr/lib/x86_64-linux-gnu/libpoppler.so.134.0.0
/usr/lib/x86_64-linux-gnu/libpoppler-cpp.so
/usr/lib/x86_64-linux-gnu/libpoppler-cpp.so.0
/usr/lib/x86_64-linux-gnu/libpoppler-cpp.so.0.11.0
/usr/lib/x86_64-linux-gnu/libpoppler-glib.so.8
/usr/lib/x86_64-linux-gnu/libpoppler-glib.so.8.26.0
/usr/lib/x86_64-linux-gnu/pkgconfig/
/usr/lib/x86_64-linux-gnu/pkgconfig/poppler.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/poppler-cpp.pc
I inspected the pkgconfig files and there were no reference to the libpoppler-cpp.so.2
file. Why is this happening? How to solve my problem?
Note
Before @Botje's suggestion to use libpoppler-cpp-dev
, I somehow installed poppler cpp using its source code compressed file (poppler-25.03.0.tar.xz). So currently I have 2 versions of poppler cpp library, one in usr/lib
and usr/include
, and another one in usr/local/lib
and usr/local/include
. In the usr/local/include
I have the libpoppler-cpp.so.2
file, so the linker is probably configured to use it instead of the shared libraries available at the usr/lib
.
main.cpp
#include <iostream>
#include "poppler-page-renderer.h"
using namespace std;
int main(int argc, char *argv[])
{
if (poppler::page_renderer::can_render() == true) cout << "Poppler can render pdf pages" << endl;
else cout << "rendering capability is not present. Please recompile the poppler cpp library with render backend 'splash'" << endl;
return 0;
}