我正在尝试使用linux(debian 64位)中的pdfium库。我设法(终于)编译了pdfium的release _x64版本,测试程序似乎可以正常工作。但是,我似乎不能在单独的项目中使用这些库。这是我的文件:
#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:
CC = g++
CFLAGS = -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
LIBS_pdfium = -static -L/usr/lib/pdfium
LDFLAGS = $(LIBS_pdfium)
Main : Main.o
${CC} ${CFLAGS} Main.o ${LDFLAGS} -o Main
Main.o : Main.cpp
${CC} ${CFLAGS} -c -std=c++11 Main.cpp
clean:
rm *o Main当我运行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中的库,但得到了相同的错误
我知道这个错误:undefined reference to FPDF_InitLibrary表示存在链接错误。因此,我使用objdump检查了/home/username/pdfium/out/Release_x64/obj中的库,其中一个库包含InitLibrary符号。这似乎没有道理..。
我不知道我是否引用了include或库中的错误路径,或者是否存在其他错误。
我试着理解chromiums插件项目makefile,因为我认为这可能会帮助我理解我应该使用什么,但不幸的是,它没有帮助。
对于我做错了什么有什么想法吗?
发布于 2016-03-30 07:59:43
要使用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_LIBSpublic/是在使用PDFium作为头文件时唯一应该使用的目录。在OSX上需要-framework AppKit。PDFium头文件是纯C格式的,但您需要-lstdc++,因为PDFium在内部使用C++,并且它需要能够链接到新的/删除。
如果你使用的是V8,你需要添加:
-lv8_libbase -lv8_libplatform -lv8_snapshot -licui18n -licuuc -licudata如果您正在使用XFA,则需要V8包含以下内容:
-lfpdfxfa -lxfa -lfx_tiff编辑最近在PDFium版本中添加了一个pdf_is_complete_lib选项。在gn args中将其设置为true将创建一个可以再次链接的libpdfium。注意,这只在禁用V8和XFA的情况下进行了测试。
发布于 2018-11-23 03:01:46
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然后是gn gen your/dir/catalog。
然后你和ninja -C your/dir/catalog pdfium_all带上pdfium.a
在Linker中
...
g++ -L-I/usr/include/glib-2.0 -o bin/debug/pdfium_test obj/debug/main.o
...您必须有-pg -s -Wl,--start-group /home/a/repo/pdfium/out/release/obj/libpdfium.a -Wl,--end-group -lpthread -ldl -lpthread
链接正常。
发布于 2020-02-17 07:49:18
我没有亲自构建它-因为它太耗时了。但我设法让它与我的golang应用程序一起使用cgo。我使用ubuntu 16.04作为我在docker中的基础镜像。这取决于https://github.com/bblanchon/pdfium-binaries
在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"]https://stackoverflow.com/questions/30600759
复制相似问题