使用ld链接器出现cannot find entry symbol __start问题

trazqian 2010-10-15 01:09:32
我在使用链接器时发生错如下,不知道怎么解决,期待高手指教!
./ld -s -o exe ji4.o gebp.o main.o
./ld: warning: cannot find entry symbol __start; defaulting to 00000000100000c0
main.o: In function `main':
main1.c:(.text+0x34): undefined reference to `atoi'
main1.c:(.text+0x54): undefined reference to `atoi'
main1.c:(.text+0x74): undefined reference to `atoi'
main1.c:(.text+0x94): undefined reference to `atoi'
main1.c:(.text+0xbc): undefined reference to `atoi'
main.o:main1.c:(.text+0xe4): more undefined references to `atoi' follow
main.o: In function `set_Matrix':
main1.c:(.text+0x1c8): undefined reference to `rand'
main.o: In function `test_Goto':
main1.c:(.text+0x2e8): undefined reference to `malloc'
main1.c:(.text+0x304): undefined reference to `malloc'
main1.c:(.text+0x320): undefined reference to `malloc'
main1.c:(.text+0x35c): undefined reference to `puts'
main1.c:(.text+0x36c): undefined reference to `exit'
main1.c:(.text+0x37c): undefined reference to `time'
main1.c:(.text+0x38c): undefined reference to `srand'
main1.c:(.text+0x448): undefined reference to `gettimeofday'
main1.c:(.text+0x4a8): undefined reference to `gettimeofday'
main1.c:(.text+0x544): undefined reference to `printf'
main1.c:(.text+0x554): undefined reference to `free'
main1.c:(.text+0x564): undefined reference to `free'
main1.c:(.text+0x574): undefined reference to `free'
main.o: In function `comp_DGEMM':
main1.c:(.text+0xf44): undefined reference to `gettimeofday'
main1.c:(.text+0xfa4): undefined reference to `gettimeofday'
main1.c:(.text+0x1080): undefined reference to `printf'
...全文
9715 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
trazqian 2010-10-17
  • 打赏
  • 举报
回复
非常感谢大家的帮助,之所以用./ld是因为我用的是交叉编译,现在问题已经解决了,的确是我少链接了一些库文件libc.so,crti.o.....,不过由于是交叉编译,需要的库文件不是原机器bin路径下的,所以链接总是有问题。
再次感谢各位的帮助O(∩_∩)O~
bluejays 2010-10-15
  • 打赏
  • 举报
回复
man ld里面给的例子是ld -o <output> /lib/crt0.o hello.o -lc
其中的ctr0.o大概是c run time之类的,5楼运行出错应该就是因为缺了这个。

也可以用gcc -v -o exe ji4.o gebp.o main.o
这样可以看到gcc的链接过程,他输出很多内容,最后一段应该就是链接的命令行。
我试了一下,看到他用了很多复杂的选项,而且链接了很多库和目标文件,比如crt1.o、crtn.o之类的
bluejays 2010-10-15
  • 打赏
  • 举报
回复
为什么是./ld
而不是ld
难道ld在当前目录下?
bluejays 2010-10-15
  • 打赏
  • 举报
回复
./ld -s -o exe ji4.o gebp.o main.o -lc
这样可以通过链接,但是运行会出错。
-lc的意思是把libc.a链接进去,那些atoi、malloc之类的函数都在这个库里
xiaocai0001 2010-10-15
  • 打赏
  • 举报
回复
为什么不用GCC去做Link, 自己调./ld?
不明白...
trazqian 2010-10-15
  • 打赏
  • 举报
回复
感谢楼上回答,但是我手动链接了 libc.so之后,出现了下述错误:
./ld: skipping incompatible /lib32/libc.so.6 when searching for /lib32/libc.so.6
./ld: cannot find /lib32/libc.so.6,但是我的lib32里没有libc.so.6文件,是我的库文件缺少文件吗?多谢了
justkk 2010-10-15
  • 打赏
  • 举报
回复
main.o ?
main1.c ?
main1.c中缺少一些头文件,添加试试
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
zhuxueling 2010-10-15
  • 打赏
  • 举报
回复 1
这几个函数是C语言基础库里的,也就是libc.so里的.
没有__start是因为c程序以main为主函数,汇编以start为主函数入口


你改用gcc连接就行了,
gcc -o exe ji4.o gebp.o main.o
这样就行了.


如果你非用ld,自己把libc.so连接上吧.

23,224

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧