libfreeimage.so: undefined reference to `png_init_filter_functions_neon‘

文章讲述了在使用freeimage库进行跨平台编译时遇到的错误,解决方法是修改pngpriv.h文件中的条件宏定义。同时提供了针对x86编译aarch64架构的Makefile.gnu设置示例。

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

交叉编译的freeimage库,在项目中编译时报错

libfreeimage.so: undefined reference to `png_init_filter_functions_neon'

解决方法
找到这个文件Source/LibPNG/pngpriv.h

#  if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \
   defined(PNG_ALIGNED_MEMORY_SUPPORTED)
#     define PNG_ARM_NEON_OPT 2
#  else
#     define PNG_ARM_NEON_OPT 0
#  endif
#endif

在这里插入图片描述
改为:

#  if defined(PNG_ARM_NEON) && (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \
   defined(PNG_ALIGNED_MEMORY_SUPPORTED)
#     define PNG_ARM_NEON_OPT 2
#  else
#     define PNG_ARM_NEON_OPT 0
#  endif
#endif

在这里插入图片描述
即可解决问题

顺带freeimage交叉编译方法,如果在x86编译aarch64架构的库
找到FreeImage的Makefile.gnu文件
在include Makefile.srcs后面输入以下内容

CROSS_COMPILE := /usr/local/orin_sdk/aarch64/bin/
CC := ${CROSS_COMPILE}aarch64-linux-gcc
CXX := ${CROSS_COMPILE}aarch64-linux-g++
LD := ${CROSS_COMPILE}aarch64-linux-ld

DESTDIR也可以改一下,这个是安装目录,也可以make install 时改
注意改一下这个

install:
	install -d $(INCDIR) $(INSTALLDIR)
	install -m 644 -o root -g root $(HEADER) $(INCDIR)
	install -m 644 -o root -g root $(STATICLIB) $(INSTALLDIR)
	install -m 755 -o root -g root $(SHAREDLIB) $(INSTALLDIR)
	ln -sf $(SHAREDLIB) $(INSTALLDIR)/$(VERLIBNAME)
	ln -sf $(VERLIBNAME) $(INSTALLDIR)/$(LIBNAME)	
#	ldconfig

将root改为自己的用户名,不然编译的库都是上锁的
编译

make -j8
make DESTDIR=安装地址 install #如果在Makefile.gnu设置了DESTDIR,直接 make install
[ 39%] Building CXX object modules/photo/CMakeFiles/opencv_photo.dir/src/tonemap.cpp.o [ 39%] Linking CXX shared library ../../lib/libopencv_imgcodecs.so /home/mao/gcc-linaro-1400-202306-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/14.0.0/../../../../aarch64-linux-gnu/bin/ld: ../../3rdparty/lib/liblibpng.a(pngrtran.c.o): in function `png_do_read_transformations': pngrtran.c:(.text.png_do_read_transformations+0x1178): undefined reference to `png_riffle_palette_neon' /home/mao/gcc-linaro-1400-202306-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/14.0.0/../../../../aarch64-linux-gnu/bin/ld: pngrtran.c:(.text.png_do_read_transformations+0x21d0): undefined reference to `png_do_expand_palette_rgba8_neon' /home/mao/gcc-linaro-1400-202306-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/14.0.0/../../../../aarch64-linux-gnu/bin/ld: pngrtran.c:(.text.png_do_read_transformations+0x325c): undefined reference to `png_do_expand_palette_rgb8_neon' /home/mao/gcc-linaro-1400-202306-x86_64_aarch64-linux-gnu/bin/../lib/gcc/aarch64-linux-gnu/14.0.0/../../../../aarch64-linux-gnu/bin/ld: ../../3rdparty/lib/liblibpng.a(pngrutil.c.o): in function `png_read_filter_row': pngrutil.c:(.text.png_read_filter_row+0xac): undefined reference to `png_init_filter_functions_neon' collect2: 错误: ld 返回 1 make[2]: *** [modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/build.make:457:lib/libopencv_imgcodecs.so.4.10.0] 错误 1 make[1]: *** [CMakeFiles/Makefile2:2515:modules/imgcodecs/CMakeFiles/opencv_imgcodecs.dir/all] 错误 2
最新发布
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值