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
儲存後
[[email protected] src]# make
/usr/local/arm/3.4.1/bin/arm-linux-gcc -o test a.c
檢視生成的檔案
[[email protected] src]# ls
a.c Makefile test
砍下檔案屬性
[[email protected] 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
儲存
生成目前系統程式
[[email protected] src]# make
gcc -o test a.c
a.c: In function ‘main’:
a.c:3: 警告:隐式聲明與内建函數 ‘printf’ 不相容
檢視檔案屬性
[[email protected] 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 下的程式
[[email protected] 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
檢視檔案屬性
[[email protected] 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