• 交叉编译器环境配置与boa嵌入式web服务器移植问题


    第一次见这种形式的sdk安装脚本:
    fsl-imx-x11-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh
    不过确实挺方便,把压缩包和脚本组合在一起,方便使用。这个sdk安装过之后,交叉编译时遇到一些问题,这里记录一下。
    这个也可以安装在wsl里面,这样可以不用虚拟机了。

    安装配置交叉编译环境

    他这个编译器安装比较简单,直接运行这个脚本即可:
    默认安装到opt下面,我这个是安装过一次了,所以会提示是否覆盖。

    sh fsl-imx-x11-glibc-x86_64-meta-toolchain-qt5-cortexa7hf-neon-toolchain-4.1.15-2.1.0.sh
    Freescale i.MX Release Distro SDK installer version 4.1.15-2.1.0
    ================================================================
    Enter target directory for SDK (default: /opt/fsl-imx-x11/4.1.15-2.1.0):
    The directory "/opt/fsl-imx-x11/4.1.15-2.1.0" already contains a SDK for this architecture.
    If you continue, existing files will be overwritten! Proceed[y/N]? y
    Extracting SDK.........................................done
    Setting it up...done
    SDK has been successfully set up and is ready to be used.
    Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
     $ . /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    这样就安装成功了,最后提示的那一句:

    . /opt/fsl-imx-x11/4.1.15-2.1.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
    
    • 1

    是配置环境变量用的,记得执行一下,然后迅速码出一个hello world来测试下交叉编译器是否能够正常使用:

    #include 
    
    int main(int argc, char **argv)
    {
            printf("hello world\n");
            return 0;
    }
    
    编译:
    arm-poky-linux-gnueabi-gcc main.c
    main.c:1:19: fatal error: stdio.h: No such file or directory
    compilation terminated.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    报错了!找不到stdio.h头文件,这可是C语言的基础头文件!提示找不到肯定还是环境变量的问题,这是需要指定sysroot的路径,如下:

    编译命令加上sysroot
    arm-poky-linux-gnueabi-gcc main.c  --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/
    
    编译错误:
    In file included from /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/features.h:392:0,
                     from /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/stdio.h:27,
                     from main.c:1:
    /opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory
    compilation terminated.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    还是报错,这个错误又不一样了,说明还是有问题,经过网上搜索发现还需要加编译参数,如下:

    编译命令:
    arm-poky-linux-gnueabi-gcc main.c  --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/ -mfloat-abi=hard -mfpu=neon
    
    这次没报错,ls查看一下,熟悉的a.out出来了
    a.out main.c
    
    • 1
    • 2
    • 3
    • 4
    • 5

    到这里编译环境算是搞好了。

    交叉编译boa

    接下来编译boa服务器,交叉编译boa服务器,可以直接修改src/Makefile,修改内容如下:

    LDFLAGS :=  -g  -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/
    
    LIBS =  
    CFLAGS = -g -O2 -pipe -Wall -I. -march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=/opt/fsl-imx-x11/4.1.15-2.1.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    记得这两行都需要修改,否则还是会报错:
    makefile
    然后就可以编译了,编译过程中如果提示bsion相关的错误,需要安装bsion:

    sudo apt-get install bison
    
    • 1

    如果出现lex 的错误,需要安装fles

    sudo apt-get install flex
    
    • 1

    更多错误参考这里吧:https://blog.csdn.net/zhangxuechao_/article/details/82821739

    这样boa就可以编译完成了;

    配置boa

    如下图是我整理的boa涉及到的文件,其中www用于存放网页文件与cgi文件,boa是可执行文件,boa.conf是boa的配置文件,这个文件需要放在/etc/boa/下面,mime.types放置的路径可以在boa.conf里配置,www的路径也可以在boa.conf里配置。
    boa
    这里的install.sh是写的一个简单的安装脚本:

    #!/bin/sh
    mkdir /var/log/
    touch /var/log/boa
    mkdir /usr/local/boa/
    mkdir /etc/boa
    cp boa /usr/local/boa/
    cp mime.types /usr/local/boa/
    cp boa.conf /etc/boa/
    cp www /usr/local/boa/ -fr
    echo "done."
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    启动boa时,有时会遇到权限问题,可以修改对应文件的所有者权限即可。

  • 相关阅读:
    SpringMVC异常处理
    同步服务器操作系统公网仓库到本地 _ 统信UOS _ 麒麟KYLINOS
    树莓派4B无屏幕连接Wi-Fi/启用ssh/创建用户
    zblog插件大全-zblog免费插件
    java-对数据结构的简单认识
    开发npm第三方库的实战经验
    支付分账户系统——新美业连锁的交易数字化破局之道
    CentOS 7 通过 yum 安装 MariaDB(Mysql)
    [安卓app毕业设计源码]精品基于Uniapp+SSM实现的家庭客栈/民宿管理系统实现的App[包运行成功]
    Spring基础篇:高级注解编程
  • 原文地址:https://blog.csdn.net/wuquan_1230/article/details/126782714