joe 发表于 2022-9-22 08:33:58

gcc的-nostdlib选项

写了一个startup.s程序,目的就是执行时调用exit退出,代码如下:
.globl _start
_start:
        mov r0,#0
        swi 0x00900001
.end

在编译时出现:
arm-none-eabi-gcc.exe startup.s -o mainhasstdlib -g
C:\Users\joe\AppData\Local\Temp\ccM6cjGa.o: In function `_start':
H:\TMP\ftpserverroot\arm9bare/startup.s:3: multiple definition of `_start'
e:/program files (x86)/gnu tools arm embedded/5.3 2016q1/bin/../lib/gcc/arm-none
-eabi/5.3.1/../../../../arm-none-eabi/lib/crt0.o:(.text+0x0): first defined here

e:/program files (x86)/gnu tools arm embedded/5.3 2016q1/bin/../lib/gcc/arm-none
-eabi/5.3.1/../../../../arm-none-eabi/lib\libg.a(lib_a-exit.o): In function `exi
t':
exit.c:(.text.exit+0x2c): undefined reference to `_exit'
e:/program files (x86)/gnu tools arm embedded/5.3 2016q1/bin/../lib/gcc/arm-none
-eabi/5.3.1/../../../../arm-none-eabi/lib/crt0.o: In function `_start':
(.text+0xec): undefined reference to `main'
collect2.exe: error: ld returned 1 exit status
所以,如果不想用到C运行时库的启动代码crt1,crti,crtend,crtn等,则:arm-none-eabi-gcc.exe startup.s -o mainnostdlib -nostdlib -g

页: [1]
查看完整版本: gcc的-nostdlib选项