Error: undefined reference to png_check_sig

本文介绍了解决使用新版本libpng库时遇到的png_check_sig函数被移除的问题。通过将gd库中的gd_png.c文件内的png_check_sig替换为png_sig_cmp,成功解决了编译错误。

undefined reference to png_check_sig

编译MRF-benchmark的时候,在编译过程中碰到 undefined reference to `png_check_sig’ 错误。
google了一下,发现由于使用的新的 libpng 1.5(1.4也是)版本,去掉了png_check_sig函数,替换为了png_sig_check函数
,于是编辑gd库的 gd_png.c文件,将

  1. if (!png_check_sig (sig, 8)) { /* bad signature */
  2. return NULL;
  3. }

修改为

  1. if (png_sig_cmp (sig, 0, 8)) { /* bad signature */
  2. return NULL;
  3. }

再次编译通过


tools/lib/ecdsa/ecdsa-libcrypto.o: In function `prepare_ctx': ecdsa-libcrypto.c:(.text+0xcd): undefined reference to `OPENSSL_init_ssl' ecdsa-libcrypto.c:(.text+0x185): undefined reference to `EC_GROUP_order_bits' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_check_signature.isra.3': ecdsa-libcrypto.c:(.text+0x3ad): undefined reference to `ECDSA_SIG_set0' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_sign': ecdsa-libcrypto.c:(.text+0x497): undefined reference to `ECDSA_SIG_get0' ecdsa-libcrypto.c:(.text+0x4ae): undefined reference to `BN_bn2binpad' ecdsa-libcrypto.c:(.text+0x4c0): undefined reference to `BN_bn2binpad' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_add_verify_data': ecdsa-libcrypto.c:(.text+0x68a): undefined reference to `EC_GROUP_order_bits' ecdsa-libcrypto.c:(.text+0x6d2): undefined reference to `EC_POINT_get_affine_coordinates' collect2: error: ld returned 1 exit status make-4.1[2]: *** [tools/dumpimage] Error 1 make-4.1[2]: *** Waiting for unfinished jobs.... tools/lib/ecdsa/ecdsa-libcrypto.o: In function `prepare_ctx': ecdsa-libcrypto.c:(.text+0xcd): undefined reference to `OPENSSL_init_ssl' ecdsa-libcrypto.c:(.text+0x185): undefined reference to `EC_GROUP_order_bits' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_check_signature.isra.3': ecdsa-libcrypto.c:(.text+0x3ad): undefined reference to `ECDSA_SIG_set0' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_sign': ecdsa-libcrypto.c:(.text+0x497): undefined reference to `ECDSA_SIG_get0' ecdsa-libcrypto.c:(.text+0x4ae): undefined reference to `BN_bn2binpad' ecdsa-libcrypto.c:(.text+0x4c0): undefined reference to `BN_bn2binpad' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_add_verify_data': ecdsa-libcrypto.c:(.text+0x68a): undefined reference to `EC_GROUP_order_bits' ecdsa-libcrypto.c:(.text+0x6d2): undefined reference to `EC_POINT_get_affine_coordinates' collect2: error: ld returned 1 exit status make-4.1[2]: *** [tools/fit_info] Error 1 tools/lib/ecdsa/ecdsa-libcrypto.o: In function `prepare_ctx': ecdsa-libcrypto.c:(.text+0xcd): undefined reference to `OPENSSL_init_ssl' ecdsa-libcrypto.c:(.text+0x185): undefined reference to `EC_GROUP_order_bits' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_check_signature.isra.3': ecdsa-libcrypto.c:(.text+0x3ad): undefined reference to `ECDSA_SIG_set0' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_sign': ecdsa-libcrypto.c:(.text+0x497): undefined reference to `ECDSA_SIG_get0' ecdsa-libcrypto.c:(.text+0x4ae): undefined reference to `BN_bn2binpad' ecdsa-libcrypto.c:(.text+0x4c0): undefined reference to `BN_bn2binpad' tools/lib/ecdsa/ecdsa-libcrypto.o: In function `ecdsa_add_verify_data': ecdsa-libcrypto.c:(.text+0x68a): undefined reference to `EC_GROUP_order_bits' ecdsa-libcrypto.c:(.text+0x6d2): undefined reference to `EC_POINT_get_affine_coordinates' collect2: error: ld returned 1 exit status make-4.1[2]: *** [tools/fit_check_sign] Error 1 make[1]: *** [tools] Error 2 Makefile:413: recipe for target 'uboot' failed make: *** [uboot] Error 2
最新发布
12-11
你看到的错误信息非常关键: ```bash undefined reference to `OPENSSL_init_ssl` undefined reference to `EC_GROUP_order_bits` undefined reference to `ECDSA_SIG_set0` undefined reference to `ECDSA_SIG_get0` undefined reference to `BN_bn2binpad` undefined reference to `EC_POINT_get_affine_coordinates` ``` 这些全部是 **OpenSSL 1.1.0+ 的函数符号**,说明你的 U-Boot 使用了 OpenSSL 进行 ECDSA 签名支持,但链接时没有正确包含 `-lcrypto`。 --- ## ✅ 根本原因总结 尽管你在 Makefile 中声明了要构建 `fit_info`, `dumpimage`, `mkimage`,但: > ❌ 缺少 `HOSTLOADLIBES_xxx = -lcrypto` > ❌ 导致链接器不知道需要链接 `libcrypto.a` 所以即使代码调用了 OpenSSL 函数,也不会去查找其实现 → 报“undefined reference” --- ## ✅ 最终修复:在 `tools/Makefile` 添加以下内容 ### 修改文件: ```bash nano ./BSP/u-boot/tools/Makefile ``` ### 在这行之后: ```makefile hostprogs-y += dumpimage mkimage ``` 👉 添加: ```makefile # Link with libcrypto for ECDSA support HOSTLOADLIBES_mkimage = -lz -lcrypto HOSTLOADLIBES_dumpimage = -lz -lcrypto ``` ### 在这行之后: ```makefile hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign ``` 👉 添加: ```makefile HOSTLOADLIBES_fit_info = -lz -lcrypto HOSTLOADLIBES_fit_check_sign = -lz -lcrypto ``` 📌 完整示例片段如下: ```makefile hostprogs-y += dumpimage mkimage HOSTLOADLIBES_mkimage = -lz -lcrypto HOSTLOADLIBES_dumpimage = -lz -lcrypto hostprogs-$(CONFIG_TOOLS_LIBCRYPTO) += fit_info fit_check_sign HOSTLOADLIBES_fit_info = -lz -lcrypto HOSTLOADLIBES_fit_check_sign = -lz -lcrypto ``` --- ## 🧠 补充说明:为什么还需要 `-lz`? - U-Boot 的 FIT 镜像使用 zlib 压缩 - `mkimage`, `fit_info` 等工具会调用 `zlib` 解压设备树或镜像 - 所以必须同时链接:`-lz -lcrypto` 否则也会报错: ``` undefined reference to inflateInit2_ ``` --- ## ✅ 确保头文件路径正确(避免编译时报错) 如果提示 `openssl/ec.h: No such file or directory`,添加: ```makefile # 自动获取 OpenSSL 头路径 HOSTCFLAGS += $(shell pkg-config --cflags libcrypto 2>/dev/null || echo -I/usr/include/openssl) ``` 放在文件顶部附近即可。 --- ## ✅ 清理并重新构建 ```bash make clean make uboot ``` 🎯 成功标志: - 不再出现 `undefined reference to ...` - 成功生成 `tools/mkimage`, `tools/dumpimage`, `tools/fit_info` - 构建过程无报错 --- ## 🔍 验证是否真的链接了 libcrypto 你可以用 `make V=1` 查看详细命令: ```bash make V=1 ``` 你会看到类似输出: ```bash gcc -o tools/mkimage tools/mkimage.o tools/lib/ecdsa/ecdsa-libcrypto.o -lz -lcrypto ``` ✅ 如果看到了 `-lcrypto`,说明修复成功! --- ## 💡 额外建议:检查配置是否启用 `CONFIG_TOOLS_LIBCRYPTO` 运行: ```bash grep CONFIG_TOOLS_LIBCRYPTO ./include/autoconf.h ``` 应该输出: ```c #define CONFIG_TOOLS_LIBCRYPTO 1 ``` 如果没有,请在 `.config` 或通过 `menuconfig` 启用它: ```bash make menuconfig ``` 路径通常是: ``` -> Tools [*] Enable crypto library support (for signature verification) ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值