C++ 在linux上链接pdfium
我正在尝试在linux(debian 64位)中使用pdfium库。我(最终)成功地编译了pdfium的发行版x64,测试程序似乎正常工作。但是,我似乎无法在单独的项目中使用这些库。 这是我的档案:C++ 在linux上链接pdfium,c++,linux,makefile,pdfium,C++,Linux,Makefile,Pdfium,我正在尝试在linux(debian 64位)中使用pdfium库。我(最终)成功地编译了pdfium的发行版x64,测试程序似乎正常工作。但是,我似乎无法在单独的项目中使用这些库。 这是我的档案: #include <iostream> #include "fpdfview.h" #include "fpdftext.h" #include "fpdfdoc.h" #include "fpdfedit.h" main(){ FPDF_InitLibrary(); std:
#include <iostream>
#include "fpdfview.h"
#include "fpdftext.h"
#include "fpdfdoc.h"
#include "fpdfedit.h"
main(){
FPDF_InitLibrary();
std::cout << "Hello World!"<<std::endl;
return 0;
}
当我运行makefile时,结果是:
g++ -Wall -g -Wno-unused-variable -Wno-reorder -I/usr/include/pdfium/core/include -I/usr/include/pdfium/fpdfsdk/include -I/usr/include/pdfium/third_party -I/usr/include/pdfium/v8/include Main.o -static -L/usr/lib/pdfium -o Main
Main.cpp:11: error: undefined reference to 'FPDF_InitLibrary'
collect2: error: ld returned 1 exit status
我还尝试使用/home/username/pdfium/out/Release_x64/obj中的库,但得到了相同的错误
我知道这个错误:对FPDF_InitLibrary的未定义引用
表示存在链接错误。因此,我使用objdump检查了/home/username/pdfium/out/releasex64/obj中的库,其中一个包含InitLibrary符号。这似乎没有道理
我不知道我指的是include或库中的错误路径,还是其他错误路径
我试图理解chromiums pdf插件项目makefile,因为我认为它可能帮助我理解我应该使用什么,但不幸的是,它没有帮助
有没有关于我做错了什么的想法?要使用PDFium进行编译,链接行将取决于您是否已将V8和/或XFA编译到PDFium二进制文件中 这两种功能均未启用时,您将需要类似的功能:
PDF_LIBS="-lpdfium -lfpdfapi -lfxge -lfpdfdoc -lfxcrt -lfx_agg \
-lfxcodec -lfx_lpng -lfx_libopenjpeg -lfx_lcms2 -lfx_freetype -ljpeg \
-lfx_zlib -lfdrm -lpdfwindow -lbigint -lformfiller -ljavascript \
-lfxedit"
PDF_DIR=<path/to/pdfium>
clang -I $PDF_DIR/public -o foo foo.c -L $PDF_DIR/out/Debug -lstdc++ -framework AppKit $PDF_LIBS
如果您使用的是XFA,则需要V8 includes plus:
-lfpdfxfa -lxfa -lfx_tiff
编辑
最近在PDFium构建中添加了一个pdf\u is\u complete\u lib
选项。在gn args
中将其设置为true
,将创建一个可以再次链接的libpdfium。注意,这仅在禁用V8和XFA的情况下进行过测试。Args文件
# Build arguments go here.
# See "gn args <out_dir> --list" for available build arguments.
is_debug = false
pdf_is_standalone = true
pdf_use_skia = false
pdf_use_skia_paths = false
pdf_enable_xfa = false
pdf_enable_v8 = false
is_component_build = false
clang_use_chrome_plugins = false
pdf_is_complete_lib = true
use_custom_libcxx = false
你一定有
-pg-s-Wl,--start group/home/a/repo/pdfium/out/release/obj/libpdfium.a-Wl,--end group-lpthread-ldl-lpthread
链接没问题。我没有亲自构建它,因为它太耗时了。但是我使用cgo使我的golang应用程序能够正常工作。我在docker中使用ubuntu 16.04作为基本映像。这取决于 下面的dockerfile下载pdfium二进制文件并链接到您正在使用pkg config开发的应用程序
FROM ubuntu:16.04
# Specify pdfium version
ARG PdfiumVersion=4026
# Install pkg-config, etc.
RUN apt-get -yqq update && apt-get clean && apt-get install -yqq apt-utils pkg-config tzdata && dpkg-reconfigure -f noninteractive tzdata
# Create .pc file for pkg-config
RUN echo "\n" \
"prefix=/home\n" \
"Name: pdfium\n" \
"Description: pdfium\n" \
"Version: $PdfiumVersion\n" \
"Requires:\n" \
"Libs: -L/home/lib -lpdfium\n" \
"Cflags: -I/home/include\n" > /home/pdfium.pc
# Download and extract pdfium binary
RUN cd /home && wget --quiet https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F$PdfiumVersion/pdfium-linux.tgz \
&& tar -xf pdfium-linux.tgz && rm pdfium-linux.tgz
# Setting up paths for pkg-config
ENV LD_LIBRARY_PATH=/home/lib
ENV PKG_CONFIG_PATH=/home/
## COPY YOUR APP TO /app/src/yourApp
# BUILD YOUR APP
WORKDIR /app/src/yourApp
# RUN your app which is linked to pdfium
ENTRYPOINT [“./yourApp"]
检查测试程序是否将fpdf包含在
外部“C”{}
块中(或者测试程序ar.C
非.cpp
,则不需要此块)。如果是这样,则必须在fpdf包含的周围添加extern“C”{}
。这是我想到的第一件事。谢谢@rudolfsfbundulis,我看了其中一个测试,它们没有外部“c”,这是一个cpp文件。在include文件中有一个extern“C”。这是否相关?如果外部“C”
正在包装您正在使用的相同include文件,那么它是相关的(准确地说,如果它在声明FPDF_InitLibrary
的include周围使用,那么它是相关的)。但是不要浪费时间在测试上——只要尝试将extern“C”{}
添加到您的应用程序中——很可能这就是您需要解决的问题。啊,对不起,我的错,我实际上没有足够注意——在makefile中,您没有指定要链接的库。LIBS\u pdfium
不应该包含要链接的库的名称吗?您只使用-L
指定了路径,但没有实际的库。能否在下面添加一个答案,列出未来搜索所需的链接标志?
# Build arguments go here.
# See "gn args <out_dir> --list" for available build arguments.
is_debug = false
pdf_is_standalone = true
pdf_use_skia = false
pdf_use_skia_paths = false
pdf_enable_xfa = false
pdf_enable_v8 = false
is_component_build = false
clang_use_chrome_plugins = false
pdf_is_complete_lib = true
use_custom_libcxx = false
...
g++ -L-I/usr/include/glib-2.0 -o bin/debug/pdfium_test obj/debug/main.o
...
FROM ubuntu:16.04
# Specify pdfium version
ARG PdfiumVersion=4026
# Install pkg-config, etc.
RUN apt-get -yqq update && apt-get clean && apt-get install -yqq apt-utils pkg-config tzdata && dpkg-reconfigure -f noninteractive tzdata
# Create .pc file for pkg-config
RUN echo "\n" \
"prefix=/home\n" \
"Name: pdfium\n" \
"Description: pdfium\n" \
"Version: $PdfiumVersion\n" \
"Requires:\n" \
"Libs: -L/home/lib -lpdfium\n" \
"Cflags: -I/home/include\n" > /home/pdfium.pc
# Download and extract pdfium binary
RUN cd /home && wget --quiet https://github.com/bblanchon/pdfium-binaries/releases/download/chromium%2F$PdfiumVersion/pdfium-linux.tgz \
&& tar -xf pdfium-linux.tgz && rm pdfium-linux.tgz
# Setting up paths for pkg-config
ENV LD_LIBRARY_PATH=/home/lib
ENV PKG_CONFIG_PATH=/home/
## COPY YOUR APP TO /app/src/yourApp
# BUILD YOUR APP
WORKDIR /app/src/yourApp
# RUN your app which is linked to pdfium
ENTRYPOINT [“./yourApp"]