undefined reference to `png_riffle_palette_neon‘错误的解决

在华为鲲鹏服务器(uos,arm架构)上编译GDAL3.1.2时遇到链接错误,涉及png库中的NEON优化函数未定义。为解决此问题,需要在pngpriv.h中添加#definePNG_ARM_NEON_OPT0,禁用特定的NEON函数调用,以消除编译错误。

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

作者:朱金灿
来源:clever101的专栏

  在uos(华为鲲鹏服务器,arm架构cpu)编译gdal3.12时出现下面错误:

/bin/bash /home/ThirdPartySrc/gdal-3.1.2/libtool --mode=link --silent g++  gdalinfo_bin.lo  /home/ThirdPartySrc/gdal-3.1.2/libgdal.la  -o gdalinfo
/usr/bin/ld: /home/ThirdPartySrc/gdal-3.1.2/.libs/libgdal.so: undefined reference to `png_riffle_palette_neon'
/usr/bin/ld: /home/ThirdPartySrc/gdal-3.1.2/.libs/libgdal.so: undefined reference to `png_do_expand_palette_rgb8_neon'
/usr/bin/ld: /home/ThirdPartySrc/gdal-3.1.2/.libs/libgdal.so: undefined reference to `png_init_filter_functions_neon'
/usr/bin/ld: /home/ThirdPartySrc/gdal-3.1.2/.libs/libgdal.so: undefined reference to `png_do_expand_palette_rgba8_neon'
collect2: error: ld returned 1 exit status
make[1]: *** [GNUmakefile:90:gdalinfo] 错误 1
make[1]: 离开目录“/home/ThirdPartySrc/gdal-3.1.2/apps”
make: *** [GNUmakefile:123:apps-target] 错误 2

  可以看出这是在arm架构编译png驱动对某个预编译宏不兼容造成的,解决办法是在pngpriv.h中添加#define PNG_ARM_NEON_OPT 0,关闭对png_riffle_palette_neon函数的调用,如下:

#define PNG_ARM_NEON_OPT 0   // 添加的代码
#ifndef PNG_ARM_NEON_OPT
   /* ARM NEON optimizations are being controlled by the compiler settings,
    * typically the target FPU.  If the FPU has been set to NEON (-mfpu=neon
    * with GCC) then the compiler will define __ARM_NEON__ and we can rely
    * unconditionally on NEON instructions not crashing, otherwise we must
    * disable use of NEON instructions.
    *
    * NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they
    * can only be turned on automatically if that is supported too.  If
    * PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail
    * to compile with an appropriate #error if ALIGNED_MEMORY has been turned
    * off.
    *
    * Note that gcc-4.9 defines __ARM_NEON instead of the deprecated
    * __ARM_NEON__, so we check both variants.
    *
    * To disable ARM_NEON optimizations entirely, and skip compiling the
    * associated assembler code, pass --enable-arm-neon=no to configure
    * or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS.
    */
#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
[ 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
发出的红包

打赏作者

clever101

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

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

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

打赏作者

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

抵扣说明:

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

余额充值