基于开源PDFium,编译动态库--Windows平台(下)

 

开篇注:博客是为了更好的思考,希望能以此记录自己的学习历程。本文写于2018年09月11日,修改于2018年09月12日。随着时间流逝,可能有些内容已经失效,望读者望文观义,get到关键点。假如对文中有啥有疑问、有想法、感觉不太对的地方欢迎留言交流~。

引言

基于谷歌开源代码修改,编译PDFium动态库–Windows平台(上)文章中我留下个坑,用上篇文章的方法编译出来windows平台32位的库,导出函数名是非C风格的。那加载动态库后解析函数不就game over了么,这篇来补个坑。

先观察

首先,先看看x86平台的库导出函数名啥形式,dumpbin -exports pdfium.dll:
图1 x86平台库导出函数名
然后想想是哪里出问题了,应该就是导出函数名那里的宏判断没有向预想的那样走下去。

查官方文档

出问题了先看看官方文档吧,这一查。。。官方在https://www.chromium.org/developers/gn-build-configuration这里这么说:

Overriding the CPU architecture
By default, the GN build will match that of the host OS and CPU architecture. To override:
target_cpu = “x86”
Possible values for the target_cpu:
Windows supports “x86” and “x64”. Since building is only supported on 64-bit machines, the default will always be “x64”.
Mac and desktop Linux supports only “x64”. On desktop Linux you might also theoretically try any of the ARM or MIPS architecture strings form the Android section below, but these aren’t supported or tested and you will also need a sysroot.
Chrome OS supports “x86” and “x64”, but to build a 32-bit binary you will need to use a sysroot on a 64-bit machine.
If you specify an Android build (see below) the default CPU architecture will be “arm”. You could try overriding it to “arm64”, “x86”, “mipsel”, or “mips64el” but the GN builds for these aren’t regularly tested.

额,这么看来好像官方对x86支持不是很好。

改代码

接下来,就考虑下改代码吧。编译生成pdfium.dll,pdfium\public文件夹下的fpdfview.h控制最外层,那就从以下代码入手

#ifdef FPDFSDK_EXPORTS
# if defined(_WIN32)
#  define FPDF_EXPORT __declspec(dllexport)
#  define FPDF_CALLCONV __stdcall
# else
#  define FPDF_EXPORT __attribute__((visibility("default")))
#  define FPDF_CALLCONV
# endif
#else
# if defined(_WIN32)
#  define FPDF_EXPORT __declspec(dllimport)
#  define FPDF_CALLCONV __stdcall
# else
#  define FPDF_EXPORT
#  define FPDF_CALLCONV
# endif
#endif

改成如下形式:

#if defined(FPDFSDK_EXPORTS)
#ifdef _WIN32
#define FPDF_EXPORT __declspec(dllexport)
#else
#define FPDF_EXPORT __attribute__ ((visibility("default")))
#endif
#else
#ifdef _WIN32
#define FPDF_EXPORT __declspec(dllimport)
#else
#define FPDF_EXPORT __attribute__ ((visibility("default")))
#endif
#endif
#define FPDF_CALLCONV

然后这时候重新gn构建,ninja执行构建,编出来的x86平台动态库就正常了。

posted @ 2018-11-13 20:00  purehol  阅读(1487)  评论(0编辑  收藏  举报