minigui:mgplus交叉编译警告 include location "/usr/include/freetype2" is unsafe for cross-compilation

本文分析了mingui的mgplus组件库在交叉编译时出现的警告原因,由于configure脚本错误地使用了主机系统的freetype库路径。通过调整环境变量PATH,确保使用目标平台的freetype库,解决了警告问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在交叉编译mingui的mgplus组件库时输出了一个警告:

mips-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../.. -D__MGPLUS_LIB__ -I.. -I../agg 
-I../../include -I../agg/font_freetype -ffunction-sections -fdata-sections 
-I/home/gyd/workspace/app/dependencies/release/freetype-2.6.1/mips-linux-gnu/include/freetype2 
-I/home/gyd/workspace/app/dependencies/release/libpng-1.2.59/mips-linux-gnu/include/libpng12 
-I/home/gyd/workspace/app/dependencies/release/zlib-1.2.11/mips-linux-gnu/include 
-I/home/gyd/workspace/app/dependencies/release/libminigui-3.2.0/mips-linux-gnu/include 
-DNDEBUG 
-I/usr/include/freetype2 
-g -O2 -MT lf_fashion.lo -MD -MP -MF .deps/lf_fashion.Tpo -c lf_fashion.cpp  -fPIC -DPIC -o .libs/lf_fashion.lo
cc1plus: warning: include location "/usr/include/freetype2" is unsafe for cross-compilation [-Wpoison-system-directories]

显然是configure生成的交叉编译Makefile文件中添加了了不该有的-I/usr/include/freetype2参数,为什么会这样呢?

为了追根溯源,我查看了mgplus项目根目录下的用于生成Makefileconfigure.ac的代码:
在这里插入图片描述
如上图红框标的代码,mgplus在生成Makefile时需要freetype的CFLAGS和LDFLAGS参数,但是它没有用标准的pkg-config命令(pkg-config --cflags freetype2,pkg-config --libs freetype2)来获取,而是用freetype提供的脚本工具 freetype-config来获取CFLAGS和LDFLAGS参数。所以在交叉编译时,如果没有将交叉编译的freetype安装路径bin文件夹加入到执行程序搜索路径环境变量$PATH,那么freetype-config --cflags返回的就是当前系统中安装的freetype的include位置/usr/include/freetype2.于是就出现了上面的警告。

解决办法也很简单在编译目标平台版本时要将交叉编译的freetype2的可执行文件夹bin加入$PATH

export PATH=$freetype_prefix/bin:$PATH

这样以来,Makefile中就freetype的include位置正确了,就不会再有这个警告

mips-linux-gnu-g++ -DHAVE_CONFIG_H -I. -I../.. -D__MGPLUS_LIB__ -I.. 
-I../agg -I../../include -I../agg/font_freetype -ffunction-sections -fdata-sections 
-I/home/gyd/workspace/app/dependencies/release/freetype-2.6.1/mips-linux-gnu/include/freetype2 
-I/home/gyd/workspace/app/dependencies/release/libpng-1.2.59/mips-linux-gnu/include/libpng12 
-I/home/gyd/workspace/app/dependencies/release/zlib-1.2.11/mips-linux-gnu/include 
-I/home/gyd/workspace/app/dependencies/release/libminigui-3.2.0/mips-linux-gnu/include 
-DNDEBUG 
-I/home/gyd/workspace/app/dependencies/release/freetype-2.6.1/mips-linux-gnu/include/freetype2 
-g -O2 -MT opt_rgba32.lo -MD -MP -MF .deps/opt_rgba32.Tpo -c opt_rgba32.cpp  -fPIC -DPIC -o .libs/opt_rgba32.lo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

10km

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值