在Ubuntu上安装交叉树莓派编译环境并传到树莓派上

一、交叉编译链搭建
1.PC机环境:

Ubuntu16.04 64位操作系统

2.交叉工具链的搭建
1)下载必要软件:

sudo apt-get install build-essential git

2)安装交叉编译环境:
3)测试交叉编译环境:
4)简单例子测试:
编写一个简单测试文件,在虚拟机上编译完成后上传到树莓派中执行:
首先创建一个hello的文件夹:

    mkdir hello
    cd hello

创建一个hello.c的文件:

   

gedit hello.c


将以下程序复制到hello.c中:

    #include <stdio.h>  
    int main(void)  
    {  
        float pi = 3.14;      
        printf("Hello World\n");  
        printf("%.2f\n",2*pi);  
    } 

创建一个Makefile的文件:

gedit Makefile


将以下程序复制到hello.c中:

    CC=arm-linux-gnueabihf-gcc  
    hello:hello.o  
    clean:  
        rm -rf hello.o hello


最后在shell上make一下
即可生成hello程序。


 

猜你喜欢

转载自blog.csdn.net/zengqz123/article/details/85127619