ADS链接脚本和makefile基础

1.ADS工程中的lds后缀的文件表示链接脚本。

SECTIONS {

    . = 0x00;

    .text  : {*(.text)}

    .rodata  ALIGN(4)  : {*(.rodata)}

    .data  ALIGN(4) : {*(.data)}

    .bs  ALIGH(4) : {*(.bss)  *(COMMON)}

}

. = 0x00表示当前地址为零,从零地址开始排放。首先是代码段,接着是只读数据段,然后是data段和bss段。这里的*表示所有文件的代码段数据段等。

在Makefile文件中有类似于:arm-linux-ld  -Tleds.lds  crt0.o  leds.o  -o  leds_elf

这一句就指定了链接顺序,指定链接的时候首先排放的crt0.o的代码段,然后排放leds.o的代码段;然后排放crt0.o的只读数据段,接着排放leds.o的只读数据段;以此类推。

2.makefile执行的条件

(1)目标不存在

(2)依赖已更新

3.一个简单的makefile

hello:hello.o a.o

    gcc hello.o a.o -o hello

hello.o:hello.c

    gcc hello.c -o hell.o -c

a.o:a.c

    gcc a.c -o a.o -c

注:-c表示只编译不链接。

4.makefile也可以用通配符来编写。

hello.o:hello.o  a.o

    gcc  -o  $@  $^

 

%.o : %.c

    gcc  -o  $@  -c  $<

clean:

    rm  *.o  hello

注释:

$@ :The file name of the target of the rule.
$^ :The names of all the prerequisites, with spaces between them.
$< :The name of the first prerequisite.

你可能感兴趣的:(linux,makefile,链接脚本,ads)