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