VS下PDF开发库PODOFO的安装编译、cmake使用的超详细说明

wxleasyland@sina.com

2020.5

 

用WIN7 X64,VS2012。

 

参考了https://blog.csdn.net/zxxSsdsd/article/details/9454629

 

一、依赖库:

freetype

简要:在“主目录”\builds\windows\vc2010 ,VS2012用这个目录的sln,选成release static方式, 这时就是变成生成lib,“多线程/MT”,生成freetype.lib。

 

libjpeg

简要:按install.txt说的,运行“VS2012 开发人员命令提示”,进入lijpeg目录,运行:NMAKE /f makefile.vs setup-v16,  打开生成的jpeg.sln,把“平台工具集”改成visual studio 2012(v110),按默认release、静态库lib、“MT”生成jpeg.lib。

 

libtiff

简要:从GnuWin32直接下Developer files,就是lib库文件,直接用头文件和libtiff.lib。

 

libpng

简要:vs2012打开“主目录”/projects/vstudio/vstudio.sln,里面已经有zlib了,可以用这里的zlib。选成“release library”,即按静态库方式生成libpng16.lib,“/MT”。 如果出错“警告被视为错误”,则属性->配置属性->c/c++->常规,将“警告视为错误”的选项改为“否”。

 

zlib 

简要:运行“VS2012 开发人员命令提示”,进入zlib-1.2.11目录下,运行:nmake -f win32\Makefile.msc LDFLAGS="-release",即可生成文件,静态库是zlib.lib、zlib.pdb。  不用命令行的话,也可以从contrib/vstudio/目录里选相应版本用VS打开进行编译。readme里有说明。

 

cppunit (optional)     不管

fontconfig (Linux/Unix only)     //windows可不管

Lua 5.1 (optional, only for podofoimpose Lua imposition plans)   //windows可不管

 

然后做podofo 0.9.6库。

podofo文件是按linux的回车,回车格式与windwos不一样!  没关系,可以不用修正过来。

 

podofo基本每个目录都有一个cmake的脚本文件CMakeLists.txt。

主目录的CMakeLists.txt,对应的是整个工程的所有项目。可以把所有子目录的项目全部转换出来。

子目录的CMakeLists.txt,对应的就是当前目录项目及子目录的项目。

只能对主目录的CMakeLists.txt进行转换,不能对子目录的CMakeLists.txt进行转换,否则cmake提示出错。

 

 

如果只对src\CMakeLists.txt进行转换,则会提示:

CMake Error at CMakeLists.txt:4 (MESSAGE): Run cmake on the CMakeLists.txt in the project root, not the one in the 'src' directory.  You will need to delete CMakeCache.txt from the current directory.

 

 

 

二、使用cmake gui界面版

(1)cmake界面版的使用方法

where is the source code目录:就是 CMakeLists.txt 所在的目录,可以把CMakeLists.txt拖进来,则这个目录就自动填上去了。

 

where to build the binaries目录:就是generate生成的项目文件会放在这里,我们要自己建一个空文件夹,再把目录指定到这个空文件夹。

 

下面的NAME、VALUE那里就是“参数栏”:  “参数”这里是叫entry,可以自已add entry、remove entry。

 

一般选中“Grouped”框、“Advanced”框

“Grouped”框 是把相同前缀的参数 放在一组。比如C_A、C_B就属于同一组,就会显示在一个组C里,这样容易看。

“Advanced”框 是显示高级参数,不选它,则一些高级参数不会显示出来。

 

configure:可以配置按哪个版本的VS来生成,然后就会自动开始配置,配置成功会显示“Configuring done”。

 

generate:就是转换生成出项目文件。在配置成功后,点这个,就可以生成项目文件了。

 

cmake 在配置时,会把找到的参数显示到“参数栏”里。我们可以对参数进行修改,或打勾等

在遇到错误,就会停止,一般这时是参数值错误,比如ZLIB_INCLUDE_DIR参数没有值,显示NOTFOUND,我们把值填上去后,再点“configure”或“generate”,就会继续。直到配置完成,显示“Configuring done”。

 

点generate进行生成,直到下面显示框显示“Generating done”,这样就成功了,目标文件夹里有生成的项目文件了。

 

我是这样设置参数:

 

FREETYPE_INCLUDE_DIR_FT2BUILD 为 E:/developer/freetype
FREETYPE_INCLUDE_DIR_FTHEADER 为 E:/developer/freetype
FREETYPE_LIBRARY_DEBUG 为 E:/developer/freetype
FREETYPE_LIBRARY_RELEASE 为 E:/developer/freetype

LIBJPEG_INCLUDE_DIR 为 E:/developer/libjpeg
LIBJPEG_LIBRARY_DEBUG 为 E:/developer/libjpeg
LIBJPEG_LIBRARY_RELEASE 为 E:/developer/libjpeg

PNG_PNG_INCLUDE_DIR 为 E:/developer/libpng
PNG_LIBRARY_DEBUG 为 E:/developer/libpng
PNG_LIBRARY_RELEASE  为 E:/developer/libpng

TIFF_INCLUDE_DIR 为 E:/developer/libtiff
TIFF_LIBRARY_DEBUG 为 E:/developer/libtiff
TIFF_LIBRARY_RELEASE 为 E:/developer/libtiff

ZLIB_INCLUDE_DIR 为 E:/developer/zlib
ZLIB_LIBRARY_DEBUG 为 E:/developer/zlib
ZLIB_LIBRARY_RELEASE 为 E:/developer/zlib

 

运行提示如下:

The C compiler identification is MSVC 17.0.61030.0

The CXX compiler identification is MSVC 17.0.61030.0

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/cl.exe

Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/cl.exe -- works

Detecting C compiler ABI info

Detecting C compiler ABI info - done

Detecting C compile features

Detecting C compile features - done

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/cl.exe

Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 11.0/VC/bin/cl.exe -- works

Detecting CXX compiler ABI info

Detecting CXX compiler ABI info - done

Detecting CXX compile features

Detecting CXX compile features - done

WANT_LIB64 unset; assuming normal library directory names

Will install libraries to C:/Program Files (x86)/PoDoFo/lib

Found zlib headers in E:/developer/zlib, library at optimized;E:/developer/zlib;debug;E:/developer/zlib

 

Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

 

Could NOT find LIBCRYPTO (missing: LIBCRYPTO_LIBRARY LIBCRYPTO_INCLUDE_DIR)

OpenSSL's libCrypto not found. Encryption support will be disabled

 

Could NOT find LIBIDN (missing: LIBIDN_LIBRARY LIBIDN_INCLUDE_DIR)

Libidn not found. AES-256 Encryption support will be disabled

 

Found LIBJPEG: optimized;E:/developer/libjpeg;debug;E:/developer/libjpeg 

Found libjpeg headers in E:/developer/libjpeg, library at optimized;E:/developer/libjpeg;debug;E:/developer/libjpeg

Found TIFF: optimized;E:/developer/libtiff;debug;E:/developer/libtiff 

Found libtiff headers in E:/developer/libtiff, library at optimized;E:/developer/libtiff;debug;E:/developer/libtiff

Found PNG: E:/developer/libpng (found version "1.6.37")

Found LibPng headers in E:/developer/libpng;E:/developer/zlib, library at E:/developer/libpng;optimized;E:/developer/zlib;debug;E:/developer/zlib

Could NOT find UNISTRING (missing: UNISTRING_INCLUDE_DIR UNISTRING_LIBRARY)

LibUnistring not found. Unistring support will be disabled

Ensure you cppunit installed version is at least 1.12.0

Cppunit not found. No unit tests will be built.

OpenSSL: Could not find the debug and release version of openssl

OpenSSL: Disabling OpenSSL

Found freetype library at optimized;E:/developer/freetype;debug;E:/developer/freetype, headers E:/developer/freetype

CMake Warning (dev) at cmake/modules/FindLIBSTLPORT.cmake:12 (SET):

  implicitly converting 'BOOLEAN' to 'STRING' type.

Call Stack (most recent call first):

  CMakeLists.txt:404 (FIND_PACKAGE)

This warning is for project developers.  Use -Wno-dev to suppress it.

 

Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE)

Could NOT find Fontconfig (missing: FONTCONFIG_LIBRARIES FONTCONFIG_INCLUDE_DIR)

Could NOT find Lua50 (missing: LUA_LIBRARIES LUA_INCLUDE_DIR)

Could NOT find Lua (missing: LUA_LIBRARIES LUA_INCLUDE_DIR)

Lua not found - PoDoFoImpose and PoDoFoColor will be built without Lua support

Building multithreaded version of PoDoFo.

Looking for pthread.h

Looking for pthread.h - not found

Found Threads: TRUE 

Building shared PoDoFo library

Pkg-config not found. No pkg-config file will be created.

Configuring done

 

WARNING: Target "podofo_shared" requests linking to directory "E:/developer/zlib".  Targets may link only to libraries.  CMake is dropping the item.

WARNING: Target "podofo_shared" requests linking to directory "E:/developer/libjpeg".  Targets may link only to libraries.  CMake is dropping the item.

WARNING: Target "podofo_shared" requests linking to directory "E:/developer/freetype".  Targets may link only to libraries.  CMake is dropping the item.

WARNING: Target "podofo_shared" requests linking to directory "E:/developer/libpng".  Targets may link only to libraries.  CMake is dropping the item.

WARNING: Target "podofo_shared" requests linking to directory "E:/developer/libtiff".  Targets may link only to libraries.  CMake is dropping the item.

 

。。。。。。

 

Generating done

 

一大堆警告,不知所云,但还是成功了。

 

这样生成项目解决方案PoDoFo.sln,打开后看,是全部的项目都集中在一起了(podofo项目、例子项目等),34个项目,非常多。大部分例子项目都生成出来了,只有少数几个没有生成出来。

podofo_shared就是podofo库dll项目,其它的都是例子项目。

 

 

(2)VS打开后的编译问题:

 

改成release方式,编译整个解决方案。

 

CreationTest项目,有一个文件提示要保存成unicode才行,并且说字符串内有换行符:

podofo-0.9.6\test\CreationTest\CreationTest.cpp : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失

podofo-0.9.6\test\CreationTest\CreationTest.cpp(52): error C2001: 常量中有换行符

看了一下,是一个日语字串:

PdfString sJap(reinterpret_cast<const pdf_utf8*>("「PoDoFo」は今から日本語も話せます。"));

WINHEX看了一下,原文件内容是按UTF8编码的,文件头没有带UTF8 BOM。

把文件另存成UTF8,不行,一样。

另存成UNICODE(代码页1200),OK,可以了。

 

 

podofo是“podofo_shared”项目,是动态库!是生成podofo.dll文件。

然后,podofo.dll没有生成,提示链接时找不到lib文件,因为链接器属性\输入\附加依赖项里,没有写上相关依赖库的lib,自己加上,再编译,就成功了。(这就是生成时出现警告的原因

 

 

(3)问题解决

其实上面在cmake中输入的参数不太对,ZLIB_INCLUDE_DIR参数是一个PATH类型,值是一个目录路径。

而ZLIB_LIBRARY_DEBUG、ZLIB_LIBRARY_RELEASE 参数是一个FILEPATH类型,值是一个文件的全路径,比如E:/developer/zlib/zlib.lib。

这样才不会出现上面的链接找不到lib的问题。

如果输入的只是一个路径,则就会出现上面的cmake警告,并且VS编译链接时找不到lib。

 

 

下面再用cmake命令行试试。

 

 

 

三、使用cmake命令行

 

(1&

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值