最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - why g++ linking the wrong poppler shared library? How to correct it? - Stack Overflow

programmeradmin1浏览0评论

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:

  1. /usr/lib/x86_64-linux-gnu/libpoppler.so
  2. /usr/lib/x86_64-linux-gnu/libpoppler.so.134
  3. /usr/lib/x86_64-linux-gnu/libpoppler.so.134.0.0
  4. /usr/lib/x86_64-linux-gnu/libpoppler-cpp.so
  5. /usr/lib/x86_64-linux-gnu/libpoppler-cpp.so.0
  6. /usr/lib/x86_64-linux-gnu/libpoppler-cpp.so.0.11.0
  7. /usr/lib/x86_64-linux-gnu/libpoppler-glib.so.8
  8. /usr/lib/x86_64-linux-gnu/libpoppler-glib.so.8.26.0
  9. /usr/lib/x86_64-linux-gnu/pkgconfig/
  10. /usr/lib/x86_64-linux-gnu/pkgconfig/poppler.pc
  11. /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;
}
发布评论

评论列表(0)

  1. 暂无评论