arm-linux下 编写Makefile

c代码 a.c如下

int main(int argc ,char **argv)
{
        printf("hello world!/n");
        return 0;
}

方法1
Makefile 内容如下

CROSS=/usr/local/arm/3.4.1/bin/arm-linux-
CC=gcc

all:
 $(CROSS)$(CC) -o test a.c

保存后
[root@5linux src]# make
/usr/local/arm/3.4.1/bin/arm-linux-gcc -o test a.c
查看生成的文件
[root@5linux src]# ls
a.c  Makefile  test
砍下文件属性
[root@5linux src]# file test
test: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

方法2 带参数
Makefile 内容如下
CROSS=
CC=gcc

all:
 $(CROSS)$(CC) -o test a.c

保存

生成当前系统程序
[root@5linux src]# make
gcc -o test a.c
a.c: In function ‘main’:
a.c:3: 警告:隐式声明与内建函数 ‘printf’ 不兼容
查看文件属性
[root@5linux src]# file test
test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped
生存arm 下的程序
[root@5linux src]# make CROSS=/usr/local/arm/3.4.1/bin/arm-linux-
/usr/local/arm/3.4.1/bin/arm-linux-gcc -o test a.c
查看文件属性
[root@5linux src]# file test
test: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.4.3, dynamically linked (uses shared libs), for GNU/Linux 2.4.3, not stripped

 

你可能感兴趣的:(arm-linux下 编写Makefile)