使用 LLVM 16.0.4 编译 MiBench 中的 tiff-v3.5.4 时遇到编译链接错误

错误信息如下

复制代码
DEBUG: We are skipping bitcode generation because we did not see any input files.
AUDIT:LINKING /root/SVF/llvm-16.0.4.obj/bin/clang [-o fax2tiff -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w -I. -I../tools -I../libtiff fax2tiff.o ../libtiff/libtiff.a]
DEBUG:Calling execCmd(/root/SVF/llvm-16.0.4.obj/bin/clang, [-o fax2tiff -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w -I. -I../tools -I../libtiff fax2tiff.o ../libtiff/libtiff.a])
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `L16toGry':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:662:(.text+0x1ee9): undefined reference to `sqrt'
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `pix24toXYZ':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:747:(.text+0x20ed): undefined reference to `exp'
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `XYZtoRGB24':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:686:(.text+0x24c7): undefined reference to `sqrt'
/opt/binutils/bin/ld: /root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:687:(.text+0x2534): undefined reference to `sqrt'
/opt/binutils/bin/ld: /root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:688:(.text+0x25a2): undefined reference to `sqrt'
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `pix16toY':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:624:(.text+0x27c7): undefined reference to `exp'
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `pix24fromXYZ':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:774:(.text+0x39f6): undefined reference to `log'
/opt/binutils/bin/ld: ../libtiff/libtiff.a(tif_luv.o): in function `pix16fromY':
/root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:638:(.text+0x3e4c): undefined reference to `log'
/opt/binutils/bin/ld: /root/mibench-master/consumer/tiff-v3.5.4/libtiff/../libtiff/tif_luv.c:640:(.text+0x3eb3): undefined reference to `log'
clang-16: error: linker command failed with exit code 1 (use -v to see invocation)
DEBUG:execCmd: /root/SVF/llvm-16.0.4.obj/bin/clang [-o fax2tiff -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w -I. -I../tools -I../libtiff fax2tiff.o ../libtiff/libtiff.a] had exitCode 1
DEBUG:execCmd: error was exit status 1
ERROR:Failed to compile using given arguments:
/root/SVF/llvm-16.0.4.obj/bin/clang [-o fax2tiff -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w -I. -I../tools -I../libtiff fax2tiff.o ../libtiff/libtiff.a]
exit status: exit status 1
DEBUG:Calling [gclang -o fax2tiff -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w -I. -I../tools -I../libtiff fax2tiff.o ../libtiff/libtiff.a] returned 1
make[1]: *** [Makefile:209:fax2tiff] 错误 1
make[1]: 离开目录"/root/mibench-master/consumer/tiff-v3.5.4/tools"
make: *** [Makefile:49:all] 错误 2

这是一个编译链接错误,主要问题是链接器找不到数学库中的函数(如sqrtexplog等)。

  • 错误类型:链接阶段未定义的引用(undefined reference)
  • 缺失的函数:sqrtexplog等数学函数
  • 问题原因:编译时没有链接数学库(libm
  • 解决方案:在编译命令中添加-lm选项来链接数学库

我的解决方案:

  1. 编辑mibench-master/consumer/tiff-v3.5.4/tools/Makefile

  2. 修改CFLAGS,在最后加上-lm

    COPTS = -std=gnu89 -O0 -Xclang -optnone -g -fno-discard-value-names -w
    OPTIMIZER=
    IPATH = -I. -I{SRCDIR} -I{LIBDIR}
    CFLAGS = {COPTS} {OPTIMIZER} ${IPATH} -lm

相关推荐
Dillon Dong1 小时前
STM32嵌入式:使用 MT29F8G08ABACAWP NAND 的FLASH全面指南
c语言·stm32
CSDN_RTKLIB2 小时前
【字符编码】有无BOM的UTF-8
c++
Chary20162 小时前
opengl 学习资料路径
c++·opengl
zhongvv2 小时前
对单片机C语言指针的一些理解
c语言·数据结构·单片机·指针·汇编语言
im_AMBER3 小时前
Leetcode 102 反转链表
数据结构·c++·学习·算法·leetcode·链表
今儿敲了吗3 小时前
01|多项式输出
c++·笔记·算法
程序员Jared3 小时前
C++11—mutex
c++
朔北之忘 Clancy3 小时前
2025 年 9 月青少年软编等考 C 语言一级真题解析
c语言·开发语言·c++·学习·数学·青少年编程·题解
量子炒饭大师4 小时前
【C++入门】Cyber底码作用域的隔离协议——【C++命名空间】(using namespace std的原理)
开发语言·c++·dubbo
REDcker4 小时前
RTCP 刀尖点跟随技术详解
c++·机器人·操作系统·嵌入式·c·数控·机床