• ARM-Linux Gcc 交叉编译环境搭建


    1 NFS网络文件系统搭建

    测试宿主机与目标板ping通

    目标板上某个文件夹(例如mnt)挂载到宿主机(192.168.1.111)的/home/nfs_dir文件夹下

    mount –t nfs –o nolock 192.168.1.111:/home/nfs_dir /mnt

    2 交叉编译环境的搭建

    参考http://linux-sunxi.org/Toolchain 通过apt-get可以很简单地安装交叉编译环境

    Ubuntu

    Recent (from12.04 on)
    A complete cross toolchain is available asa package, just run:

    apt-get install gcc-arm-linux-gnueabihf

    Debian

    Details on Cross-development Toolchainsfor Debian are at the DebianWiki.
    Note: Debian now hascross-toolchains in the archive, superseding those at emdebian.org

    Currently (December 2015) available forunstable and testing in the standard repositories.

    Install Cross Compiler and build utilities:

    dpkg --add-architecture armhf
    apt-get update
    apt-get install g++-arm-linux-gnueabihf
    

    安装之后在终端输入 arm 按下tab 并且自动补全之后,输入

    arm-linux-gnueabihf-gcc -v
    

    如果安装成功终端会打印出以下信息:

    Using built-in specs.
    
    COLLECT_GCC=arm-linux-gnueabihf-gcc
    
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.7/lto-wrapper
    
    Target: arm-linux-gnueabihf
    
    Configured with: ../src/configure -v--with-pkgversion='Ubuntu/Linaro 4.7.1-5ubuntu1~ppa1'--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr--program-suffix=-4.7 --enable-shared --enable-linker-build-id--with-system-zlib --libexecdir=/usr/lib --without-included-gettext--enable-threads=posix--with-gxx-include-dir=/usr/arm-linux-gnueabihf/include/c++/4.7.1 --libdir=/usr/lib--enable-nls --enable-clocale=gnu --enable-libstdcxx-debug--enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm--enable-plugin --enable-objc-gc --enable-multilib --disable-sjlj-exceptions--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb--disable-werror --enable-checking=release --build=x86_64-linux-gnu--host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf---includedir=/usr/arm-linux-gnueabihf/include--with-headers=/usr/arm-linux-gnueabihf/include--with-libs=/usr/arm-linux-gnueabihf/lib
    
    Thread model: posix
    
    gcc version 4.7.1 (Ubuntu/Linaro4.7.1-5ubuntu1~ppa1)
    

    3 环境变量

    apt-get方式进行安装已经配置好了环境变量,如果自己下载源码编译安装或者直接安装bin文件,则还需要设置环境变量(链接)

    vi /etc/bash.bashrc   
    export PATH=$PATH:编译器安装路径 
    source /root/.bashrc 
    

    安装完交叉编译器,就可以生成目标板的可执行程序

    遇到以下问题

    1 运行程序时提示“-sh: ./pl: not found”

    解决办法

    目标板上没有运行程序所需要的库,查看所需要的库的方法

    readelf -ahello | grep NEEDED
    最后终端会打印出该程序执行的依赖库,将相应的库拷贝的lib文件夹下即可。

    注意:该依赖库需要使用相同版本的交叉编译器

    解决方法:
    方法1、 把这些所需要的库拷贝到板子上,保证板子上找得到。

    方法2、 编译的时候使用静态编译,arm-linux-gcc-o hello hello.c -static

  • 相关阅读:
    多媒体笔记
    全部MIME类型列表
    PHP 标记 <?= <?php
    js渐显文字 时间间隔
    ThinkPHP5 隐式传参的获取方法
    [php] Fatal error: Class Exception not found in
    ionic2 The --v1 and --v2 flags have been removed.
    java POI导出excel,合并单元格边框消失
    swagger暴露程序接口文档
    SpringBoot整合Mybatis
  • 原文地址:https://www.cnblogs.com/unclemac/p/12783415.html
Copyright © 2020-2023  润新知