【笔记】freetype 2.9 与 libpng 1.2.x setjmp冲突问题

freetype 依赖libpng, 我采用的freetype 版本是2.9 libpng版本是1.2.8

问题

编译freetype2.9 时,遇到如下错误字段:
这段话来自 libpng的头文件, pngconf.h

          __pngconf.h__ already includes setjmp.h;
         __dont__ include it again.;

意思是freetype 里也include 了setjmp.h?

查看 freetype 代码。果然

freetype-2.9/src/sfnt/pngshim.c:30: /* We always include <setjmp.h>, so make libpng shut up! */

似乎freetype 与 libpng 有着不可描述的故事,很有意思。

解决方法:

诚然这个问题,可通过升级libpng的版本解决。(实测用1.6.x的 libpng不会出现该问题)

但项目中,SDK中是基于libpng1.2.8 , 为了兼容SDK, 还是硬着头皮编译吧。
把freetype中include “setjmp.h” 的地方挪到一个新的头文件中,
在没有include libpng头文件, 而又需要setjmp的地方,再include 这个新的头文件。
在freetype里几处调整之后,最终可以编译通过,
整理补丁如下,

diff -Naurp freetype-2.9_org/include/for_png_1_2_X.h freetype-2.9/include/for_png_1_2_X.h
--- freetype-2.9_org/include/for_png_1_2_X.h	1970-01-01 08:00:00.000000000 +0800
+++ freetype-2.9/include/for_png_1_2_X.h	2020-09-04 15:29:42.428884604 +0800
@@ -0,0 +1,17 @@
+/*
+Fix setjmp.h conflict when using png 1.2.X
+*/
+#ifndef FOR_PNG_1_2_X_H
+#define FOR_PNG_1_2_X_H
+
+#include <setjmp.h>
+
+#define ft_jmp_buf     jmp_buf  /* note: this cannot be a typedef since */
+                                /*       jmp_buf is defined as a macro  */
+                                /*       on certain platforms           */
+
+#define ft_longjmp     longjmp
+#define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */
+
+#endif
+
diff -Naurp freetype-2.9_org/include/freetype/config/ftstdlib.h freetype-2.9/include/freetype/config/ftstdlib.h
--- freetype-2.9_org/include/freetype/config/ftstdlib.h	2020-09-04 15:33:27.253502905 +0800
+++ freetype-2.9/include/freetype/config/ftstdlib.h	2020-09-04 15:31:56.921021663 +0800
@@ -152,7 +152,7 @@
   /*                                                                    */
   /**********************************************************************/
 
-
+#if 0  /*move it to "for_png_1_2_X.h" when using png1.2.X. fix setjmp.h conflict issue*/
 #include <setjmp.h>
 
 #define ft_jmp_buf     jmp_buf  /* note: this cannot be a typedef since */
@@ -161,7 +161,7 @@
 
 #define ft_longjmp     longjmp
 #define ft_setjmp( b ) setjmp( *(ft_jmp_buf*) &(b) ) /* same thing here */
-
+#endif
 
   /* the following is only used for debugging purposes, i.e., if */
   /* FT_DEBUG_LEVEL_ERROR or FT_DEBUG_LEVEL_TRACE are defined    */
diff -Naurp freetype-2.9_org/include/freetype/internal/ftvalid.h freetype-2.9/include/freetype/internal/ftvalid.h
--- freetype-2.9_org/include/freetype/internal/ftvalid.h	2020-09-04 15:33:27.253502905 +0800
+++ freetype-2.9/include/freetype/internal/ftvalid.h	2020-09-04 15:32:23.158323991 +0800
@@ -22,6 +22,7 @@
 #include <ft2build.h>
 #include FT_CONFIG_STANDARD_LIBRARY_H   /* for ft_setjmp and ft_longjmp */
 
+#include "for_png_1_2_X.h"
 
 FT_BEGIN_HEADER
 
diff -Naurp freetype-2.9_org/src/sfnt/pngshim.c freetype-2.9/src/sfnt/pngshim.c
--- freetype-2.9_org/src/sfnt/pngshim.c	2020-09-04 15:33:27.217502806 +0800
+++ freetype-2.9/src/sfnt/pngshim.c	2020-09-04 15:32:10.170055530 +0800
@@ -34,6 +34,7 @@
 
 #include "sferrors.h"
 
+#include "for_png_1_2_X.h"
 
   /* This code is freely based on cairo-png.c.  There's so many ways */
   /* to call libpng, and the way cairo does it is defacto standard.  */
diff -Naurp freetype-2.9_org/src/smooth/ftgrays.c freetype-2.9/src/smooth/ftgrays.c
--- freetype-2.9_org/src/smooth/ftgrays.c	2020-09-04 15:33:27.221502818 +0800
+++ freetype-2.9/src/smooth/ftgrays.c	2020-09-04 15:32:00.928953980 +0800
@@ -285,6 +285,7 @@ typedef ptrdiff_t  FT_PtrDist;
 #define Smooth_Err_Memory_Overflow  Smooth_Err_Out_Of_Memory
 #define ErrRaster_Memory_Overflow   Smooth_Err_Out_Of_Memory
 
+#include "for_png_1_2_X.h"
 
 #endif /* !STANDALONE_ */
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值