裸机程序编译时出现未定义函数处理方法

编译时出现了如下的编译错误

lcd/s3c2440_lcd_controller.o(.text+0xb4): In function `s3c2440_lcd_controller_init':
: undefined reference to `__floatsidf'
lcd/s3c2440_lcd_controller.o(.text+0xd0): In function `s3c2440_lcd_controller_init':
: undefined reference to `__divdf3'
lcd/s3c2440_lcd_controller.o(.text+0xec): In function `s3c2440_lcd_controller_init':
: undefined reference to `__divdf3'
lcd/s3c2440_lcd_controller.o(.text+0x108): In function `s3c2440_lcd_controller_init':
: undefined reference to `__subdf3'
lcd/s3c2440_lcd_controller.o(.text+0x124): In function `s3c2440_lcd_controller_init':
: undefined reference to `__adddf3'
lcd/s3c2440_lcd_controller.o(.text+0x138): In function `s3c2440_lcd_controller_init':
: undefined reference to `__fixdfsi'
Makefile:14: recipe for target 'all' failed

是因为如下的代码使用了除法
int clkval = (double)HCLK/plcdparams->time_seq.vclk/2-1+0.5;
其实这个project里面是由一个包含除法运算的库,可能无法满足吧。
解决出现未定义函数的方法
1、如果是比较简单的可以自己写一个,但是通常这些问题都比较复杂,所以建议没有必要这样做
2、在uboot源码中查找,因为目前写的是裸板程序,uboot是裸板程序的集大成者
3、可以在linux源码上找
4、在相关库上面找

这个未定义函数我们在uboot和linux中都没有找到,所以只能在库中查找,函数库一般都在编译器目录下
操作如下

zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ echo %$PATH
%/home/book/bin:/home/book/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/work/tools/gcc-3.4.5-glibc-2.3.6/bin:/snap/bin
zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ arm-linux-g
arm-linux-g++        arm-linux-gcc        arm-linux-gcc-3.4.5  arm-linux-gccbug     arm-linux-gcov       arm-linux-gprof      
zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ arm-linux-g
arm-linux-g++        arm-linux-gcc        arm-linux-gcc-3.4.5  arm-linux-gccbug     arm-linux-gcov       arm-linux-gprof      
zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ arm-linux-gc
arm-linux-gcc        arm-linux-gcc-3.4.5  arm-linux-gccbug     arm-linux-gcov       
zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ arm-linux-gcc -v
Reading specs from /work/tools/gcc-3.4.5-glibc-2.3.6/lib/gcc/arm-linux/3.4.5/specs
Configured with: /work/tools/create_crosstools/crosstool-0.43/build/arm-linux/gcc-3.4.5-glibc-2.3.6/gcc-3.4.5/configure --target=arm-linux --host=i686-host_pc-linux-gnu --prefix=/work/tools/gcc-3.4.5-glibc-2.3.6 --with-float=soft --with-headers=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux/include --with-local-prefix=/work/tools/gcc-3.4.5-glibc-2.3.6/arm-linux --disable-nls --enable-threads=posix --enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c,c++ --enable-shared --enable-c99 --enable-long-long
Thread model: posix
gcc version 3.4.5
zhengzheng:~/filefromwin/learning/008_font_017_009 - 副本$ cd
zhengzheng:~$ cd /work/tools/gcc-3.4.5-glibc-2.3.6/
zhengzheng:/work/tools/gcc-3.4.5-glibc-2.3.6$ ls
arm-linux  arm-linux.crosstoolconfig.txt  bin  distributed  include  info  lib  libexec  man  tmp
zhengzheng:/work/tools/gcc-3.4.5-glibc-2.3.6$ grep __floatsidf * -nR
Binary file arm-linux/lib/libm.so matches
Binary file arm-linux/lib/libiberty.a matches
Binary file arm-linux/lib/libgcc_s.dir/libgcc_s.so.1 matches
Binary file arm-linux/lib/libgcc_s.dir/libgcc_s.so matches
Binary file arm-linux/lib/libc.so.6 matches
Binary file arm-linux/lib/libc-2.3.6.so matches
Binary file arm-linux/lib/libm.so.6 matches
Binary file arm-linux/lib/libm-2.3.6.so matches
Binary file arm-linux/lib/libc.a matches
Binary file arm-linux/lib/libgcc_s.so.1 matches
Binary file arm-linux/lib/libgcc_s.so matches
Binary file arm-linux/lib/libm.a matches
Binary file arm-linux/bin/localedef matches
Binary file arm-linux/bin/sprof matches
distributed/info/gccint.info:556: -- Runtime Function: double __floatsidf (int I)
Binary file distributed/info/gccint.info matches
Binary file distributed/lib/gcc/arm-linux/3.4.5/libgcc.a matches
Binary file distributed/include/c++/3.4.5/arm-linux/bits/stdc++.h.gch/O0g matches
Binary file distributed/include/c++/3.4.5/arm-linux/bits/stdc++.h.gch/O2g matches
Binary file distributed/arm-linux/lib/libm.so matches
Binary file distributed/arm-linux/lib/libiberty.a matches
Binary file distributed/arm-linux/lib/libgcc_s.dir/libgcc_s.so.1 matches
Binary file distributed/arm-linux/lib/libgcc_s.dir/libgcc_s.so matches
Binary file distributed/arm-linux/lib/libc.so.6 matches
Binary file distributed/arm-linux/lib/libc-2.3.6.so matches
Binary file distributed/arm-linux/lib/libm.so.6 matches
Binary file distributed/arm-linux/lib/libm-2.3.6.so matches
Binary file distributed/arm-linux/lib/libc.a matches
Binary file distributed/arm-linux/lib/libgcc_s.so.1 matches
Binary file distributed/arm-linux/lib/libgcc_s.so matches
Binary file distributed/arm-linux/lib/libm.a matches
Binary file distributed/arm-linux/bin/localedef matches
Binary file distributed/arm-linux/bin/sprof matches
Binary file include/c++/3.4.5/arm-linux/bits/stdc++.h.gch/O0g matches
Binary file include/c++/3.4.5/arm-linux/bits/stdc++.h.gch/O2g matches
info/gccint.info:556: -- Runtime Function: double __floatsidf (int I)
Binary file info/gccint.info matches
Binary file lib/gcc/arm-linux/3.4.5/libgcc.a matches
Binary file tmp/arm-linux-hello2-static matches

首先 找出我们的环境变量路径 命令:echo $PATH
然后查看我们当前使用的gcc版本 命令:arm-linux-gcc -v
然后根据环境变量找到的路径,进入gcc的目录中查询相关函数
命令:grep __floatsidf *nR
因为动态库是执行时动态链接,比较麻烦,所以我们直接找静态库,将相关的几个静态库复制到project中

然后可以修改makefile挨个尝试,也可以为了避免尝试把它们全部都加上
修改如下

 13 all: $(objs)
 14         #arm-linux-ld -Ttext 0 -Tdata 0x30000000  start.o led.o uart.o init.o main.o -o sdram.elf
 15         arm-linux-ld -T sdram.lds $^ libgcc.a -o sdram.elf

然后编译成功。

如果您对我写的有疑问,欢迎提出,大家互相学习,共同进步

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值