build_embed_linux_system

嵌入式Linux平台软件的交叉编译

Linux平台软件安装是软件源提供一套兼容当前系统的编译好的工具,通过apt命令下载安装的过程,不一定是新版本,而是整合成系统包时的版本。而软件编译则不同,可以去各软件官网查询最新的版本,进行编译。这里建议选择最新的LTS版本,对于Linux平台工具的编译,可能依赖gcc/g++, make,python2/python3,perl,scons等工具,如果编译时缺失,根据实际情况去下载更新。另外还有一些软件依赖某些基础组件如libssl.so,libcrypto.so,libzlib.so,可以使用指令sudo apt-get install libexe.so进行更新下载,不过即使更新后,也可能因为版本过低不支持某些api导致编译失败,这就需要对依赖的库同样进行编译。一个复杂的Linux工具的编译,往往除本身的编译外,还涉及相关支持库的编译,这就大大增加了难度。对于交叉编译,因为不能依赖直接安装的库文件,往往需要按照依赖关系编译所有的库,这就对开发者有了更高的要求。

本节目录如下所示。

cross_compiler_base

对于linux平台的软件的交叉编译,如何总结其实是很复杂的问题。不同版本的系统,不同芯片平台,甚至不同版本的编译器,编译时面临的问题可能都不同,除非直接使用虚拟机或者docker进行完整的复制,否则面对的情况都可能不同,这里列出我编译时遇到的问题和我的解决办法。

#以-lssl为例
apt search libssl

#如果显示过多,不知道安装版本,可通过
apt --names-only search libssl

#第一个libssl-dev即为编译的库
sudo apt install libssl-dev

上面就是交叉编译时遇到的常见问题分类,在实际开发过程中要根据情况,具体问题具体分析,有些软件只需要configure配置下,有些软件直接就没考虑交叉编译的环境支持(mosquitto,nginx等),就需要去修改软件的Makefile和configure来满足要求,记住这些开源库其实也是软件,是可以直接去修改和配置的,如果能够掌握shell,并理解cmake语法,那么这些问题都有相应的解决方法。本篇中很多软件都是按照上述思路进行交叉编译的,当然这些软件也只是Linux系统软件的冰山一脚,后续会持续更新。

注意:交叉编译时,一定要重定义安装目录,否则会替换系统中的库文件,此时会因为平台差异导致无法链接和运行,反而影响系统功能使用。.

cross_compiler_tools

对于交叉编译,安装目录统一为: ${SUPPORT_ENV_INSTALL}, 可在编译前自定义

#存放安装信息的目录(根据实际地址定义)
export SUPPORT_ENV_INSTALL="/home/freedom/Desktop/user_git/sdk/arm/install"

注意: 本小节使用的软件源码地址有可能因为版本的迭代在官网被移除,导致下载失败。如果遇到这种问题,建议直接去对应官网下载。

bash_cross_compiler

Bash是一种广泛使用的Unix shell和命令语言,是脚本执行的基础环境。

# 下载bash, 并解压文件
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/bash/bash-5.2.21.tar.gz
tar -xvf bash-5.2.21.tar.gz
cd  bash-5.2.21/

./configure --prefix="${SUPPORT_ENV_INSTALL}" --host=arm-none-linux-gnueabihf
make -j4 && make install

can_cross_compiler

can相关的交叉编译软件主要是用于can使能的iproute2和can操作的can-utils,编译方法如下所示。

# 下载iproute2

# 下载can-utils
wget https://github.com/linux-can/can-utils
# 执行编译
./autogen.sh 
./configure --prefix="${SUPPORT_ENV_INSTALL}" --target=arm-linux-gnueabihf --host=arm-linux-gnueabihf --enable-shared
make -j4 && make install

zlib_cross_compiler

zlib是一个广泛使用的数据压缩库,它提供了用于数据压缩和解压缩的API。

# 下载zlib, 并解压文件
wget http://www.zlib.net/zlib-1.3.tar.gz
tar -xvf zlib-1.3.tar.gz

cd zlib-1.3/

# 配置zlib编译环境,并编译
export CHOST=arm-none-linux-gnueabihf
./configure --prefix="${SUPPORT_ENV_INSTALL}"
make -j4 && make install

openssl_cross_compiler

OpenSSL是一个开放源代码的软件库包,实现了SSL及相关加密技术,为应用程序提供安全通信的能力。其编译需要依赖Perl的支持,且版本大于5.10。目前Ubuntu系统是自带的,不需要安装。

# 下载并解压openssl
wget https://www.openssl.org/source/openssl-3.1.4.tar.gz
tar -xvf openssl-3.1.4.tar.gz

cd openssl-3.1.4/

export CC=gcc
export CXX=g++

# 通过perl完成Makefile的生成
./config --cross-compile-prefix=arm-none-linux-gnueabihf- no-asm --prefix="${SUPPORT_ENV_INSTALL}" linux-armv4
make -j4 && make install

注意:openssl一定要确保下载完成,否则编译时可能显示缺少OpenSSL::fallback.

openssh_cross_compiler

OpenSSH是SSH(Secure Shell)协议的免费开源实现,它提供了服务端后台程序和客户端工具,用于加密远程控制和文件传输过程中的数据。

# 下载并解压openssh
wget https://mirrors.tuna.tsinghua.edu.cn/OpenBSD/OpenSSH/portable/openssh-8.9p1.tar.gz
tar -xvf openssh-9.5p1.tar.gz

# 进入并配置指定ssl和zlib
cd openssh-9.5p1/
./configure --host=arm-none-linux-gnueabihf --with-libs --with-zlib="${SUPPORT_ENV_INSTALL}"/ --with-ssl-dir="${SUPPORT_ENV_INSTALL}" --disable-etc-default-login

# 执行编译步骤
make -j4

编译完成后,目录下的scp sftp ssh sshd ssh-add ssh-agent ssh-keygen ssh-keyscan文件,即是编译后的执行文件.

上传文件到嵌入式linux平台,并创建运行环境。

创建以下目录(存在则不需要创建)。

mkdir /usr/local/bin
mkdir /usr/local/etc
mkdir /usr/libexec
mkdir /var/run
mkdir /var/empty

将scp, sftp, ssh, sshd, ssh-agent, ssh-keygen, ssh-keyscan拷贝到/usr/local/bin目录.

将sftp-server, ssh-keysign, sshd-session拷贝到/usr/libexec目录.

将moduli, ssh_config, sshd_config拷贝到/usr/local/etc目录.

在嵌入式平台生成ssh对应密钥.

cd /usr/bin/etc
/usr/local/bin/ssh-keygen -t rsa -f ssh_host_rsa_key -N ""
/usr/local/bin/ssh-keygen -t dsa -f ssh_host_dsa_key -N ""
/usr/local/bin/ssh-keygen -t ecdsa -f ssh_host_ecdsa_key -N ""
/usr/local/bin/ssh-keygen -t dsa -f ssh_host_ed25519_key -N ""

生成完成后,在/etc/passwd中添加sshd用户支持。

# /etc/passwd
sshd:x:115:65534::/var/run/sshd:/usr/sbin/nologin

# 创建运行目录
mkdir -p /var/empty

当然也要和上面桌面端一样,在/usr/local/etc/sshd_config添加支持的加密算法,然后执行。

# sshd_config
############################################################
PermitRootLogin yes
PasswordAuthentication yes

#定义ssh支持的算法,客户端和服务器需要一致
Ciphers aes128-cbc
MACs  hmac-md5
KexAlgorithms diffie-hellman-group1-sha1,ecdh-sha2-nistp256
#############################################################

/usr/local/bin/sshd -f /usr/local/etc/sshd_config

另外,将相应的动态库(libssl.so, libcrypto.so等)也要复制到嵌入式Linux平台下的/usr/lib/目录下。

mosquitto_cross_compiler

mosquitto是一款开源的消息代理软件,它实现了MQTT协议。mosquitto的编译依赖openssl和cJSON(来自于github的开源方案),如果只是想编译mosquitto库, 首先去github下载cJSON库。

进入修改Makefile,将“CC = gcc -std=c89”替换如下CC = arm-none-linux-gnueabihf-gcc -std=c89

执行如下命令编译。

cd cJSON/
export PREFIX="${SUPPORT_ENV_INSTALL}"
make -j4 && make install

此时在/home/program/install/arm就有编译mosquitto的全部库和头文件支持,下面进行mosquitto的编译。

# 下载mosquitto
wget https://mosquitto.org/files/source/mosquitto-2.0.18.tar.gz
tar -xvf mosquitto-2.0.18.tar.gz
cd mosquitto-2.0.18/

# 编译mosquitto
export CC=gcc
export CXX=g++
export CPPFLAGS="-I${SUPPORT_ENV_INSTALL}/include/ -fPIC"
export CFLAGS="-I${SUPPORT_ENV_INSTALL}include/ -fPIC"
export LDFLAGS="-L${SUPPORT_ENV_INSTALL}lib -fPIC -lssl -lcrypto"
export DESTDIR="${SUPPORT_ENV_INSTALL}/mosquitto"
export CROSS_COMPILE=arm-none-linux-gnueabihf-
make -j4 && make install

# 嵌入式端启动mosquitto的方法
/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf &

pcer_cross_compiler

pcer是一个用C语言编写的库,它实现了与Perl 5相同的正则表达式语法和语义。

#下载pcer
wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.bz2
tar -xvf pcre-8.37.tar.bz2

cd pcre-8.37/
export CC=arm-none-linux-gnueabihf-gcc
export CXX=arm-none-linux-gnueabihf-g++
./configure --prefix="${SUPPORT_ENV_INSTALL}" --host=arm-none-linux-gnueabihf

#编译和安装
make -j4 && make install

nginx_cross_compiler

Nginx是一个高性能的HTTP和反向代理web服务器,同时也是一个IMAP/POP3/SMTP代理服务器

#下载nginx和rtmp插件
wget http://nginx.org/download/nginx-1.25.3.tar.gz
git clone https://github.com/arut/nginx-rtmp-module.git
 
#安装支持库
sudo apt-get install zlib1g-dev libpcre-ocaml-dev -y

tar -xvf nginx-1.25.3.tar.gz
cd nginx-1.25.3/
export CC=gcc

#修改auto/types/sizeof中的值,影响autoconf的生成
vim auto/types/sizeof
#--------------------------------------------------------
ngx_size=4
#--------------------------------------------------------

./configure --prefix="${SUPPORT_ENV_INSTALL}" --with-http_ssl_module --with-http_mp4_module --with-http_v2_module --without-http_upstream_zone_module --add-module=/home/program/download/source/nginx-rtmp-module

#修改objs/Makefile的开头
vim objs/Makefile
#--------------------------------------------------------
CC=arm-none-linux-gnueabihf-gcc
CFLAGS=-pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g 
CPP=${CC} -E
LINK=$(CC)
CFLAGS+=-I "${SUPPORT_ENV_INSTALL}"/include
LINK+=-L "${SUPPORT_ENV_INSTALL}"/lib
#--------------------------------------------------------

#编译和安装
make -j4 && make install

nginx添加rtmp配置支持,并使用ffmpeg进行推流

vim /etc/nginx/conf/nginx.conf

#增加如下rtmp推流网址
events {
    worker_connections 1024;
}

rtmp {
    server {
        listen 1935;
        chunk_size 4096;

        application live {
            allow publish 127.0.0.1;
            allow play all;
            live on;
            record off;
            meta copy;
        }

        application hls {
            live on;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 8s;
        }
    }
}

nginx -c /etc/nginx/conf/nginx.conf

#推流命令(循环)
ffmpeg -re -stream_loop -1 -i /home/program/0001.mp4 -codec copy -map 0 -f flv rtmp://127.0.0.1/live/mytest

ffmpeg_cross_compiler

ffmpeg是一套可以用来记录、转换数字音频、视频,并能将其转化为流的开源计算机程序,它提供了录制、转换以及流化音视频的完整解决方案。

# 下载ffmeg源代码
wget https://ffmpeg.org/releases/ffmpeg-6.1.tar.xz
tar -xvf ffmpeg-6.1.tar.xz
cd ffmpeg-6.1/ 

# 配置编译环境并进行编译
./configure --arch=arm --target-os=linux --cross-prefix=arm-none-linux-gnueabihf- --prefix="${SUPPORT_ENV_INSTALL}"
make -j4 && make install

alsa_cross_compiler

ALSA(Advanced Linux Sound Architecture)是一种为Linux系统和其他类Unix系统设计的音频架构

# 下载alsa源代码
wget http://www.alsa-project.org/files/pub/lib/alsa-lib-1.2.11.tar.bz2
tar -xvf alsa-lib-1.2.11.tar.bz2
cd alsa-lib-1.2.11/

# 配置编译环境并进行编译
export CC=arm-none-linux-gnueabihf-gcc
./configure --host=arm-linux --prefix="${SUPPORT_ENV_INSTALL}" --enable-shared=yes --enable-static=no --disable-python --with-configdir=/share/alsa
make -j6

# 执行make install需要在root权限下,还需要arm编译器
sudo su
export PATH="$PATH:/home/freedom/.../toolchain"
make install

编译应用组件alsa-utils

# 下载alsa-utils源代码
wget http://www.alsa-project.org/files/pub/utils/alsa-utils-1.2.11.tar.bz2
tar -xvf alsa-utils-1.2.11.tar.bz2
cd alsa-utils-1.2.11/

# 配置编译环境并进行编译
./configure CC=arm-none-linux-gnueabihf-gcc LDFLAGS="-L"${SUPPORT_ENV_INSTALL}"/lib -lasound -latopology" CFLAGS="-I${SUPPORT_ENV_INSTALL}/include" --host=arm-linux --prefix="${SUPPORT_ENV_INSTALL}" --enable-static --disable-xmlto --disable-alsamixer --with-libiconv-prefix="${SUPPORT_ENV_INSTALL}" --with-systemdsystemunitdir="${SUPPORT_ENV_INSTALL}"/lib/systemd/system --with-udev-rules-dir="${SUPPORT_ENV_INSTALL}"/lib/udev/rules.d --with-asound-state-dir="${SUPPORT_ENV_INSTALL}"/var/lib/alsa
make -j6 && make install

libnl_cross_compiler

libnl(Netlink Library)是一个应用于Linux系统的开源库,它提供了一套基于Netlink协议通信的API接口。

# 下载libnl源代码
wget https://www.infradead.org/~tgr/libnl/files/libnl-3.2.25.tar.gz
tar -xvf libnl-3.2.25.tar.gz
cd libnl-3.2.25

# 配置编译环境并进行编译
./configure --host=arm-none-linux-gnueabihf --prefix=${SUPPORT_ENV_INSTALL} 
make -j4 && make install

sqlite_cross_compiler

SQLite是一款轻型的数据库,它是遵守ACID的关系型数据库管理系统,并包含在一个相对小的C库中。

# 下载sqlite源码
wget https://www.sqlite.org/2023/sqlite-autoconf-3440200.tar.gz
tar -xvf sqlite-autoconf-3440200.tar.gz
cd sqlite-autoconf-3440200/

# 配置编译环境并进行编译
./configure CC=arm-none-linux-gnueabihf-gcc CXX=arm-none-linux-gnueabihf-g++  --host=arm-linux --prefix="${SUPPORT_ENV_INSTALL}"
make -j4 && make install

minicom_cross_compiler

Minicom是Linux下一个非常流行的串口通信工具,它类似于Windows下的超级终端,被广泛应用于与串口设备的通信。

# 下载ncurses源码
wget https://ftp.gnu.org/gnu/ncurses/ncurses-6.4.tar.gz
tar -xvf ncurses-6.4.tar.gz
cd ncurses-6.4

# 配置编译环境并进行编译
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}"--without-tests --with-shared  --disable-stripping --without-progs
make && make install
# 下载minicom源码
wget http://deb.debian.org/debian/pool/main/m/minicom/minicom_2.8.orig.tar.bz2
tar -xvf minicom_2.8.orig.tar.bz2
cd minicom_2.8.orig

# 配置编译环境并进行编译
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" CPPFLAGS=-I/home/freedom/sdk/arm/install/include/ncurses LDFLAGS=-L/home/freedom/sdk/arm/install/lib
make && make instal

###
# issue fix:编译失败修改更新src/winodows.c,在全局变量定义中添加
# 在gcc11.2不存在此变量定义,因此添加
###
static const char *BC;

# 文档说明
2004-12-29  Adam Lackorzynski  <adam@os.inf.tu-dresden.de>

  * src/window.c: Do not declare static char *BC, it is also
                  defined in /usr/include/termcap.h and breaks
                  to compile with gcc-4.0.

curl_cross_compiler

Curl是一个命令行工具,也用于在编程中作为一个库(libcurl),它支持多种协议的数据传输。

# 下载curl源码
wget https://mirrors.tuna.tsinghua.edu.cn/debian/pool/main/c/curl/curl_8.8.0.orig.tar.gz
tar -xvf curl_8.8.0.orig.tar.gz
cd curl-8.8.0/

# 配置编译环境并进行编译
./configure --with-ssl="${SUPPORT_ENV_INSTALL}" --with-zlib="${SUPPORT_ENV_INSTALL}" --host=arm-none-linux-gnueabihf --target=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" --enable-shared=0

make -j6 && make install

# 安装curl运行的证书,否则不支持ssl访问
wget https://curl.se/ca/cacert.pem
curl --cacert /etc/cacert.pem  "https://devapi.qweather.com/v7/weather/now?location=101210301&key=***"

ser2net_cross_compiler

ser2net是桥接网络连接与各种串行设备的工具。

# 下载ser2net源码
wget https://mirrors.tuna.tsinghua.edu.cn/debian/pool/main/s/ser2net/ser2net_3.5.orig.tar.gz
tar -xvf ser2net_3.5.orig.tar.gz
cd ser2net-3.5/

# 配置编译环境并进行编译
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}"
make -j4 && make install

# ser2net应用方法
ser2net -n -C 2000:raw:600:/dev/tty0:9600 NONE 1STOPBIT 8DATABITS LOCAL -RTSCTS

libffi_cross_compiler

LibFFI是一个开源的C库,它允许程序员在运行时动态地调用任何具有已知参数和返回类型的函数。

# 下载libffi源码
wget https://codeload.github.com/libffi/libffi/zip/refs/heads/master
mv master libffi-master.zip
unzip libffi-master.zip
cd libffi-master/

# 配置编译环境并进行编译
./autogen.sh
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}"
make && make install

log4cplus_cross_compiler

log4cplus是一个开源的C++日志库,它提供了线程安全、灵活且多粒度控制的日志记录功能。

# 下载log4cplus源码
wget https://github.com/log4cplus/log4cplus/releases/download/REL_2_1_1/log4cplus-2.1.1.tar.gz
tar -xvf log4cplus-2.1.1.tar.gz
cd log4cplus-2.1.1/

# 配置编译环境并进行编译
./configure --enable-threads=yes --host=arm-none-linux-gnueabihf LDFLAGS="-lpthread" --prefix="${SUPPORT_ENV_INSTALL}"
make && make install

lrzsz_cross_compiler

lrzsz是一款在Linux系统中常用的文件传输工具,它可以代替传统的FTP工具进行文件的上传和下载操作。

buildroot系统添加lrzsz支持路径: Target Packages>Networking application>lrzsz

# 下载lrzsz源码
wget https://ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz
tar -xvf lrzsz-0.12.20.tar.gz
cd lrzsz-0.12.20

# 配置编译环境并进行编译
CFLAGS=-O2 CC=arm-none-linux-gnueabihf-gcc ./configure --prefix="${SUPPORT_ENV_INSTALL}" --cache-file=arm-linux-cache
make && make install

# 使用方法
# 1. 在SerialCRT里通过 相应串口=>会话选项=>X/Y/Zmoderm配置上传和下载目录
# 2. 串口连接设备,执行lsz, lrz分别进行下载和上传文件

psplash_cross_compiler

psplash是Linux系统中的一个工具,主要用于在系统启动过程中显示启动画面。

# 下载pshflash源码
wget https://git.yoctoproject.org/psplash/snapshot/psplash-master.tar.gz
tar -xvf psplash-master.tar.gz
cd psplash-master/

# 安装支持库
sudo apt-get install libgdk-pixbuf2.0-dev

# 生成背景image头文件
# psplash-poky.png替换启动背景图
# psplash-bar.png替换启动动作条
./make-image-header.sh base-images/psplash-poky.png POKY
./make-image-header.sh base-images/psplash-bar.png BAR

# 执行脚本
aclocal
autoheader
automake --add-missing
autoconf

# 配置编译环境并进行编译
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}"
make -j8 && make install

# psplash默认写入地址为/run/psplash_fifo
# echo "PROGRESS 10" > /run/psplash_fifo
#######################################################
# /etc/init.d/rcS修改
/bin/psplash --angle 0 &

for i in /etc/init.d/S??* ;do

    #....

    # 写入psplash-write修改进度条,可以在gui启动前写入fifo修改数据
    progress=$(($progress+20))
    if type psplash-write >/dev/null 2>&1; then
        psplash-write "PROGRESS $progress" || true
    fi
done
########################################################

opencv_cross_compiler

# 下载opencv源码
wget https://codeload.github.com/opencv/opencv/tar.gz/refs/tags/4.10.0
mv 4.10.0 opencv-4.10.0.tar.gz
tar -xvf opencv-4.10.0.tar.gz
cd opencv-4.10.0/

# 修改CMakeList指定编译版本
vim CMakeLists.txt

#=================================================================
set(CMAKE_C_COMPILER arm-none-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-none-linux-gnueabihf-g++)
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(arm ON)
set(GCC_COMPILER_VERSION "" CACHE STRING "GCC Compiler version")
set(GNU_MACHINE "aarch64-linux-gnu" CACHE STRING "GNU compiler triple")
#=================================================================

# 指定编译脚本
mkdir build install
cd build/

cmake -DCMAKE_INSTALL_PREFIX=../install \
-D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_FAT_JAVA_LIB=OFF \
-D BUILD_ANDROID_PROJECTS=OFF \
-D WITH_OPENCL=OFF \
-D BUILD_PNG=ON \
-D BUILD_JPEG=ON \
-D WITH_CUDA=OFF \
-D WITH_GSTREAMER=OFF \
-D WITH_1394=OFF \
-D WITH_GTK=OFF \
-D BUILD_SHARED_LIBS=ON \
-D BUILD_opencv_world=ON ..

# 编译和安装opencv
make -j4 && make install

wpa_supplicant

wget http://deb.debian.org/debian/pool/main/libn/libnl3/libnl3_3.7.0.orig.tar.gz
tar -xvf libnl3_3.7.0.orig.tar.gz

cd libnl3_3.7.0/
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" --enable-shared --enable-static

make -j4 && make install
wget http://deb.debian.org/debian/pool/main/e/expat/expat_2.5.0.orig.tar.gz
tar -xvf expat_2.5.0.orig.tar.gz

cd expat_2.5.0/
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" --enable-shared --enable-static 

make -j4 && make install
wget http://deb.debian.org/debian/pool/main/d/dbus/dbus_1.14.10.orig.tar.xz
tar -xvf dbus_1.14.10.orig.tar.xz

cd dbus_1.14.10
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" CFLAGS=-I${SUPPORT_ENV_INSTALL}/include LDFLAGS=-L${SUPPORT_ENV_INSTALL}/lib --enable-shared --enable-static

make -j10 && make install
wget https://w1.fi/releases/wpa_supplicant-2.11.tar.gz
tar -xvf wpa_supplicant-2.11.tar.gz

cd wpa_supplicant-2.11/wpa_supplicant/
cp defconfig .config

############################
CC = arm-none-linux-gnueabihf-gcc

CFLAGS += -I${SUPPORT_ENV_INSTALL}/include
LIBS += -L${SUPPORT_ENV_INSTALL}/lib
LIBS += -lssl -lcrypto
#############################

make -j10

sudo cp wpa_cli wpa_supplicant ${SUPPORT_ENV_INSTALL}/bin
vi /etc/wpa_supplicant.conf

# /etc/wpa_supplicant.conf
# ssid对应账号,psk对应密码,通过iwlist查看
ctrl_interface=/var/run/wpa_supplicant
ap_scan=1
network={
 ssid="xxx"
 psk="xxx"
}

ifconfig wlan0 up
wpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 & 

# 等待连接成功
# wlan0: CTRL-EVENT-CONNECTED - Connection to 98:0d:51:3c:77:6c completed [id=0 id_str=]

udhcpc -i wlan0 &

# ping测通讯情况
ping -I 192.169.3.170 www.baidu.com

在rcS中添加开机自动查询wifi,并连接。

# buildroot系统
vi /etc/init.d/rcS

################################################################
ifconfig wlan0 up
wpa_supplicant -D wext -c /etc/wpa_supplicant.conf -i wlan0 &
udhcpc -b -i wlan0 -p /var/run/udhcpc.pid -R &
#################################################################

libmodbus_cross_compiler

# 下载地址
https://github.com/stephane/libmodbus

# 解压libmodbus
unzip libmodbus-master.zip
cd libmodbus-master/

./autogen.sh
./configure --host=arm-none-linux-gnueabihf --prefix="${SUPPORT_ENV_INSTALL}" --enable-shared --enable-static

make -j8 && make install

next_chapter

返回目录

直接开始下一章节:Linux快速部署SDK方法