http://strayingworm.blog.163.com/blog/static/197234037201363113154429/
Poppler 是功能强大的 PDF 渲染编辑库。Poppler-Qt4 项目开发了 Poppler 的 Qt4 API,非常实用。
[http://poppler.freedesktop.org/] Poppler Project
[http://people.freedesktop.org/~aacid/docs/qt4/] The Poppler Qt4 interface library
这里我们在 Windows 下,利用静态编译的 Qt 4.8.5 静态编译 Poppler, Poppler-Qt4 及所依赖的各个库。
(1) 使用 MinGW,没有使用 Visual C++。
比如安装路径 C:\MinGW,bin 路径 C:\MinGW\bin。MSYS 终端启动文件 C:\MinGW\msys\1.0\msys.bat
(2) 设置Qt路径
这里是静态编译poppler,故需要静态编译了的Qt库,比如在 C:\Qt\QtStatic\4.8.5 。在 MSYS 终端环境下的路径为 /C/Qt/QtStatic/4.8.5
(3) 运行进入 MSYS 终端
运行 C:\MinGW\msys\1.0\msys.bat
比如 Win+R 运行 C:\MinGW\msys\1.0\msys.bat
export RebuildDir=/C/Qt/Poppler-Static-Rebuild
export QtDir=/C/Qt/QtStatic/4.8.5
Lib | Download From | Extract Into | Header Path | Header Dependency |
Lib Dependency |
zlib | http://www.zlib.net/ | zlib-1.2.8 | zlib-1.2.8 | ||
libpng | http://www.libpng.org/pub/png/libpng.html | png-1.6.2 | png-1.6.2 | zlib | -lz |
freetype | http://download.savannah.gnu.org/releases/freetype/ | freetype-2.5.0 | freetype-2.5.0/include | png | -lpng16 -lz |
libiconv | MinGW/include MinGW/lib | iconv-mingw32 | iconv-mingw32 | ||
libxml2 | ftp://xmlsoft.org/libxml2/ | xml2-2.9.1 | xml2-2.9.1/include | ||
fontconfig | http://www.freedesktop.org/software/fontconfig/release/ | fontconfig-2.10.93 | fontconfig-2.10.93 | xml2,freetype | -lxml2 -liconv -lfreetype -lpng16 -lz |
pixman | http://www.cairographics.org/releases/ | pixman-0.30.0 | pixman-0.30.0/pximan | png | -lpng16 -lz |
cairo | http://www.cairographics.org/releases/ | cairo-1.12.14 | cairo-1.12.14/src | pixman,fontconfig, freetype,png,zlib |
-lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -lpng16 -lz |
libjpeg | http://www.ijg.org/files/ | jpeg-8d | jpeg-8d | ||
libtiff | ftp://ftp.remotesensing.org/pub/libtiff/ | tiff-4.0.3 | tiff-4.0.3/libtiff | ||
lcms2 | http://sourceforge.net/projects/lcms | lcms2-2.5 | lcms2-2.5/include | tiff,jpeg,zlib | -ltiff -ljpeg -lz |
openjpeg | http://code.google.com/p/openjpeg/downloads/list | openjpeg-1.5.1 | openjpeg-1.5.1/libopenjpeg | lcms2,tiff,png,zlib | -llcms2 -ljpeg -ltiff -lpng16 -lz |
poppler | http://poppler.freedesktop.org/ | poppler-0.23.4 | poppler-0.23.4/poppler |
export CFLAGS="-march=i486 -mms-bitfields -mthreads" export CPPFLAGS="-DG_ATOMIC_OP_USE_GCC_BUILTINS=1" cd ${RebuildDir}/pkg-config-0.28 ./configure --enable-static --with-internal-glib make 成功之后拷贝 pkg-config.exe 到 ${RebuildDir} 备用。 cp .libs/pkg-config.exe ../ cd ../
cd ${RebuildDir}/zlib-1.2.8/ make -fwin32/Makefile.gcc cp libz.a ../ cd ../
cd ${RebuildDir}/png-1.6.2/ export CPPFLAGS="-I${RebuildDir}/zlib-1.2.8" export LDFLAGS="-L${RebuildDir}" ./configure --enable-static make cp .libs/libpng16.a ../ cd ../
cd ${RebuildDir}/freetype-2.5.0 export CPPFLAGS= export LDFLAGS= export LIBPNG_CFLAGS="-I${RebuildDir}/png-1.6.2" export LIBPNG_LDFLAGS="-L${RebuildDir} -lpng16 -lz" ./configure --enable-static --with-png --without-zlib (use internal zlib) make cp objs/.libs/libfreetype.a ../ cd ../
mkdir ${RebuildDir}/iconv-mingw32 cp /C/MinGW/lib/libiconv.a ${RebuildDir}/ cp /C/MinGW/include/iconv.h ${RebuildDir}/iconv-mingw32/
cd ${RebuildDir}/xml2-2.9.1 export CFLAGS="-DLIBICONV_STATIC -DLIBXML_STATIC" export CPPFLAGS= export LDFLAGS="-L${RebuildDir}" export LIBS="-liconv" ./configure --enable-static --with-sax1 --with-iconv --without-ftp --without-http make cp .libs/libxml2.a ../ cd ../
cd ${RebuildDir}/fontconfig-2.10.93 export CFLAGS="-DLIBICONV_STATIC -DLIBXML_STATIC" export CPPFLAGS= export LDFLAGS="-L${RebuildDir}" export LIBS="-lfreetype -lxml2 -liconv -lpng16 -lz" export FREETYPE_CFLAGS="-I${RebuildDir}/freetype-2.5.0/include" export FREETYPE_LIBS="-lfreetype" export LIBXML2_CFLAGS="-I${RebuildDir}/xml2-2.9.1/include" export LIBXML2_LIBS="-lxml2" ./configure --enable-static --enable-libxml2 make cp src/.libs/libfontconfig.a ../ cd ../
cd ${RebuildDir}/pixman-0.30.0 export CFLAGS= export CPPFLAGS= export LDFLAGS= export LIBS= export PNG_CFLAGS="-I${RebuildDir}/png-1.6.2" export PNG_LIBS="-L${RebuildDir} -lpng16 -lz" ./configure --enable-static --enable-libpng make cp pixman/.libs/libpixman-1.a ../ cd ../
export RebuildDir=/C/Gnu/Qt/QtProgramme/CrabPDF-Poppler-Static-Rebuild-Final cd ${RebuildDir}/cairo-1.12.12 export CFLAGS="-DLIBICONV_STATIC -DLIBXML_STATIC -D_SSIZE_T_DEFINED" export CPPFLAGS="-I${RebuildDir}/zlib-1.2.8" export LDFLAGS="-L${RebuildDir}" export LIBS= export png_CFLAGS="-I${RebuildDir}/png-1.6.2" export png_LIBS="-lpng16 -lz" export png_REQUIRES="nothing" export FREETYPE_CFLAGS="-I${RebuildDir}/freetype-2.5.0/include" export FREETYPE_LIBS="-lfreetype" export FONTCONFIG_CFLAGS="-I${RebuildDir}/fontconfig-2.10.93" export FONTCONFIG_LIBS="-lfontconfig -lxml2 -liconv" export pixman_CFLAGS="-I${RebuildDir}/pixman-0.30.0/pixman" export pixman_LIBS="-lpixman-1" export PKG_CONFIG="${RebuildDir}/pkg-config.exe" ./configure --enable-static --disable-qt --disable-win32 --disable-win32-font --enable-fc --enable-ft --enable-png --enable-ps --enable-pdf --disable-xlib --disable-xcb --disable-xlib-xrender --disable-pthread --host=i686-pc-mingw32 --enable-test-surfaces make cp src/.libs/libcairo.a ../ cd ../
cd ${RebuildDir}/poppler-0.23.4 export CFLAGS="-DOPJ_STATIC -DLIBICONV_STATIC -DLIBXML_STATIC" export CXXFLAGS="-DOPJ_STATIC -DLIBICONV_STATIC -DLIBXML_STATIC" export CPPFLAGS="-I${RebuildDir}/zlib-1.2.8" export LDFLAGS="-L${RebuildDir}" export LIBS= export MOCQT4="${QtDir}/bin/moc.exe" export LIBPNG_CFLAGS="-I${RebuildDir}/png-1.6.2" export LIBPNG_LIBS="-lpng16 -lz" export FREETYPE_CFLAGS="-I${RebuildDir}/freetype-2.5.0/include" export FREETYPE_LIBS="-lfreetype -lpng16 -lz" export FONTCONFIG_CFLAGS="-I${RebuildDir}/fontconfig-2.10.93" export FONTCONFIG_LIBS="-lfontconfig -lfreetype -lxml2 -liconv -lpng16 -lz" export CAIRO_CFLAGS="-I${RebuildDir}/cairo-1.12.12/src -I${RebuildDir}/freetype-2.5.0/include" export CAIRO_LIBS="-lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -ljpeg -lpng16 -lz" export LIBJPEG_CFLAGS="-I${RebuildDir}/jpeg-8d -I/C/MinGW/include -L${RebuildDir} -L/C/MinGW/lib" export LIBJPEG_LIBS="-ljpeg -L/C/MinGW/lib -lm" export LIBTIFF_CFLAGS="-I${RebuildDir}/tiff-4.0.3/libtiff" export LIBTIFF_LIBS="-ltiff" export LCMS_CFLAGS="-I${RebuildDir}/lcms2-2.5/include" export LCMS_LIBS="-llcms2 -ljpeg -ltiff -lz" export LIBOPENJPEG_CFLAGS="-I${RebuildDir}/openjpeg-1.5.1/libopenjpeg" export LIBOPENJPEG_LIBS="-lopenjpeg -llcms2 -ltiff -lpng16 -lz" export PDFTOCAIRO_CFLAGS="-I${RebuildDir}/cairo-1.12.12/src -I${RebuildDir}/freetype-2.5.0/include -I${RebuildDir}/fontconfig-2.10.93" export PDFTOCAIRO_LIBS="-lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -ljpeg -lpng16 -lz" export POPPLER_QT4_CFLAGS="-I${QtDir}/include" export POPPLER_QT4_LIBS="-L${QtDir}/lib -lQtTest -lQtGui -lQtXml -lQtCore -lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -ljpeg -lopenjpeg -llcms2 -lpng16 -lz -lGdi32 -lOle32 -lOleAut32 -lImm32 -lWinSpool -lWinMM -lComDlg32 -lWS2_32 -lUuid" export POPPLER_QT4_TEST_CFLAGS="-I${QtDir}/include" export POPPLER_QT4_TEST_LIBS="-L${QtDir}/lib -lQtTest -lQtGui -lQtXml -lQtCore -lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -ljpeg -lopenjpeg -llcms2 -lpng16 -lz -lGdi32 -lOle32 -lOleAut32 -lImm32 -lWinSpool -lWinMM -lComDlg32 -lWS2_32 -lUuid" export PKG_CONFIG="${RebuildDir}/pkg-config.exe" ./configure --enable-static --enable-libtiff --enable-poppler-qt4 --disable-poppler-qt5 --disable-poppler-cpp --disable-gtk-test --with-testdatadir=test make cp poppler/.libs/libpoppler.a ../ cp qt4/src/.libs/libpoppler-qt4.a ../ cd ../
试着进入该文件所在目录手动编译 cd qt4/src/ gcc test-poppler-qt4.cpp -I${QtDir}/include -I${RebuildDir}/poppler-0.23.4/poppler -I${RebuildDir}/poppler-0.23.4/qt4/src -I${RebuildDir}/zlib-1.2.8 -fno-exceptions -fno-check-new -fno-common -DOPJ_STATIC -D_WIN32_IE=0x0500 -L${RebuildDir} -lpoppler-qt4 -lpoppler -lopenjpeg -llcms2 -ltiff -lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -lpng16 -lz -L${QtDir}/lib -lQtTest -lQtGui -lQtXml -lQtCore -lGdi32 -lOle32 -lOleAut32 -lImm32 -lWinSpool -lWinMM -lComDlg32 -lWS2_32 -lUuid 还是通不过。 看错误提示,显示Undefined reference to operator new(unsigned int)大量报错,问题在于需要用g++而非gcc,白痴了…… g++ test-poppler-qt4.cpp -I${QtDir}/include -I${RebuildDir}/poppler-0.23.4/poppler -I${RebuildDir}/poppler-0.23.4/qt4/src -I${RebuildDir}/zlib-1.2.8 -fno-exceptions -fno-check-new -fno-common -DOPJ_STATIC -D_WIN32_IE=0x0500 -L${RebuildDir} -lpoppler-qt4 -lpoppler -lopenjpeg -llcms2 -ltiff -lcairo -lpixman-1 -lfontconfig -lxml2 -liconv -lfreetype -lpng16 -lz -L${QtDir}/lib -lQtTest -lQtGui -lQtXml -lQtCore -lGdi32 -lOle32 -lOleAut32 -lImm32 -lWinSpool -lWinMM -lComDlg32 -lWS2_32 -lUuid 还是通不过。 看错误提示,发现Poppler的函数是有_imp_前缀的,这意味着这些函数头文件中一定定义了__declspec(dllexport)或__declspec(dllimport)。 查看库文件包含的函数名称,是静态函数名称 nm ../src/libpoppler_qt4_la-poppler-document.o | grep Poppler8Document16setRenderBackend nm ../../../libpoppler-qt4.a | grep Poppler8Document16setRenderBackend 看来还是要找到在静态编译中还是会强制定义 dllexport 和 dllimport 的头文件。发现qt4\src\poppler-export.h 和 cpp\poppler-global.h 是这样的,它们包含了dllexport和dllimport的定义。手动编辑删除相应内容 "__declspec(dllexport)", "__declspec(dllimport)" 即可。
${QtDir}/src/3rdparty/libtiff/libtiff/tif_strip.c 与 ${RebuildDir}/tiff-4.0.3/libtiff/tif_strip.c ${QtDir}/src/3rdparty/libtiff/libtiff/tiffio.h 与 ${RebuildDir}/tiff-4.0.3/libtiff/tiffio.h edit ${RebuildDir}/poppler-0.23.4/qt4/src/libpoppler-qt4.la replace "${RebuildDir}/poppler-0.23.4/poppler/libpoppler.la" with "-L"${RebuildDir}/poppler-0.23.4/poppler/.libs -lpoppler"
${RebuildDir}/poppler-0.23.4/qt4/tests/stress-threads-qt4.cpp edit ${RebuildDir}/poppler-0.23.4/qt4/tests/stress-threads-qt4.cpp add line #include <QtTest/QTest> replace "sleep(duration);" with "QTest::qSleep(duration);" edit ${RebuildDir}/poppler-0.23.4/qt4/tests/Makefile add "-lQtTest" in this var "POPPLER_QT4_LIBS" exactly before "-lQtGui"
则在 LDFLAGS 变量中,可以不用 -L/path/to/lib/dir 而用 -Wl,R/path/to/lib/dir