能否将printf函数以静态形式链接进汇编程序?
我在网上搜了很久很久了...因此请各位耐心看。下面两段程序:
test.asm
-------------
[section .text]
global _start
extern hello
_start:
push dword 1234
call hello
hello.c
-------------
int hello(int a){
printf("a is %d",a);
return 0;
}
linux下输入命令:
gcc -c hello.c //成功执行
nasm -f elf -o test.o test.asm//成功执行
ld ld -static -o test test.o hello.o -lc //关键是这一句,输出的错误我不敢全贴出来(太长了),怕把人吓跑了。
----------------------报错--------------------------
/usr/lib/libc.a(syslog.o): In function `closelog':
(.text+0xc9): undefined reference to `_Unwind_Resume'
/usr/lib/libc.a(syslog.o): In function `openlog':
(.text+0x344): undefined reference to `_Unwind_Resume'
/usr/lib/libc.a(syslog.o): In function `__vsyslog_chk':
(.text+0x85a): undefined reference to `_Unwind_Resume'
/usr/lib/libc.a(syslog.o): In function `__vsyslog_chk':
...还有很多很多
---------------------------------------------------------
请高手赐教!
----------------------------------------------------------
我说一点自己的想法:将printf以静态库方式链接进程序,我只能做到一部分,请看下面一段程序:
h.c
---------------------------------------------------------
int main(void){
printf("hello linux");
return 0;
}
linux下输入命令:
gcc -c h.c //执行成功
gcc -static -lc -o h h.o //执行成功
生成的可执行文件h体积是574631字节(显然是链接入了静态库)
但问题是:一旦像上面在汇编文件里用到了_start,gcc就不能参与第二步的链接了,用ld吧,也不行...