編譯環境:VMware+ubuntu
交叉編譯器:arm-linux-gcc-4.4.3
1.Ubuntu編寫hello.c程序
#include <stdio.h>
int main(void)
{
printf("hello,world!\n");
return 0;
}
2.在Ubuntu上使用arm-linux-gcc編譯:
arm-linux-gcc -o hello hello.c
此時在ubuntu上執行會提示:
3.通過串口或者U盤等方式將生成的hello可執行文件拷貝到ARM開發板上
運行hello可執行文件
./hello
運行結果:
出錯原因:
因爲程序使用的是動態鏈接方式編譯的,而ARM上的鏈接庫文件路徑不同,導致找不到文件,可以用gcc -static命令改用靜態鏈接的方式編譯。
在Ubuntu上重新編譯:
arm-linux-gcc -o hello hello.c -static
生成hello可執行文件,拷貝到ARM板,使用./hello執行
4.結果:
運行成功