1

我正在尝试学习链接器脚本这是我的文件

调用者.c

extern void hello();

void main()
{
    hello();

}

helloasm.c

   #include <stdio.h>

    void hello()
    {
        printf("\nHELLO\n\n");
    }

链接.lds

    SECTIONS
    {
      . = 0x10000;
      .text : { *(.text) }
      . = 0x8000000;
      .data : { *(.data) }
      .bss : { *(.bss) }
    }

编译.sh

    cc -S helloasm.c   #generate assembly file
    cc -c helloasm.s   #generate object file
    cc -c caller.c       #generate object file

    ld -o hello -T link.lds helloasm.o caller.o

当我使用

cc caller.c helloasm.c

我得到输出 HELLO

但是当调用 sh 文件时出现错误 **

helloasm.o: In function `hello':
helloasm.c:(.text+0xe): undefined reference to `puts'

** 有人可以解释为什么 puts 函数是未定义的

GNU ld (GNU Binutils for Ubuntu) 2.23.2

gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
4

0 回答 0