求助:如何让linux下ld自动检查.a包中的函数重名
时间:2011-06-28
来源:互联网
有两个c文件,t.c和t2.c,分别定义了一个函数ttt();
按说编译之后再链接时,应该报错: multiple definition of `ttt'。但实际情况却是:
1) 如果我编译出两个obj(t.obj t2.obj),然后ld 这两个obj,的确会报错:
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c
[root@localhost temp]# ld t.obj t2.obj
t2.obj: In function `ttt':
t2.c:(.text+0x0): multiple definition of `ttt'
t.obj:t.c:(.text+0xf): first defined here
但是,如果我把两个.obj ar成一个.a包,再针对.a包进行ld,则不会报错:
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c;ar crus t.a t.obj t2.obj
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c;ar crus t.a t.obj t2.obj;ld --start-group t.a --end-group -e main
[root@localhost temp]#
现在我们代码工程很大,而且是分模块维护,互相之间通过.a进行版本共享,避免不了这个问题。
此问题原来被我发在 CSDN-CSDN社区-Linux/Unix社区-专题技术讨论区 ,
http://topic.csdn.net/u/20110624/08/e42379c4-bffc-46bb-81e9-7bbc6f4cec3f.html
解决办法是使用nm报错:
nm -s software.a s5348.a drv_platform.a|awk 'toupper($2)==($2) {print $3}'|sort|uniq -d
但是nm写在makefile中不方便,而且此种做法有很多误报,工程大了改不过来。
希望这里的大大们能帮忙支招。多谢了!
按说编译之后再链接时,应该报错: multiple definition of `ttt'。但实际情况却是:
1) 如果我编译出两个obj(t.obj t2.obj),然后ld 这两个obj,的确会报错:
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c
[root@localhost temp]# ld t.obj t2.obj
t2.obj: In function `ttt':
t2.c:(.text+0x0): multiple definition of `ttt'
t.obj:t.c:(.text+0xf): first defined here
但是,如果我把两个.obj ar成一个.a包,再针对.a包进行ld,则不会报错:
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c;ar crus t.a t.obj t2.obj
[root@localhost temp]# gcc -o t2.obj -c t2.c;gcc -o t.obj -c t.c;ar crus t.a t.obj t2.obj;ld --start-group t.a --end-group -e main
[root@localhost temp]#
现在我们代码工程很大,而且是分模块维护,互相之间通过.a进行版本共享,避免不了这个问题。
此问题原来被我发在 CSDN-CSDN社区-Linux/Unix社区-专题技术讨论区 ,
http://topic.csdn.net/u/20110624/08/e42379c4-bffc-46bb-81e9-7bbc6f4cec3f.html
解决办法是使用nm报错:
nm -s software.a s5348.a drv_platform.a|awk 'toupper($2)==($2) {print $3}'|sort|uniq -d
但是nm写在makefile中不方便,而且此种做法有很多误报,工程大了改不过来。
希望这里的大大们能帮忙支招。多谢了!
作者: Solmyr_biti 发布时间: 2011-06-28
这个问题,我也没涉及到,等高人来看看吧.帮你顶了.
作者: abao623660072 发布时间: 2011-06-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28