libwebsockets是一个高性能的开源C语言库,专为实现WebSocket协议及相关的HTTP协议而设计。它不仅使开发者能够在客户端与服务器端轻松构建WebSocket连接,还可以用作标准HTTP服务器。WebSocket是一种在单个TCP连接上进行全双工通信的协议,可以促进浏览器与服务器间实时、互动数据交换的能力,为现代网络应用提供了强大的支持。
libwebsockets在处理如HTTPS和WSS等安全连接时,依赖于OpenSSL提供的强大加密功能来保障数据的安全性。同时,为了提高网络传输效率,libwebsockets还利用ZLib库进行数据压缩。因此,在交叉编译libwebsockets库之前需要先交叉编译OpenSSL和ZLib这两个依赖库。接下来,将跟各位小伙伴详述将这三大库移植至ELF 1开发板的具体步骤。
交叉编译链:arm-poky-linux-gnueabi-gcc
内核版本:Linux4.1.15
elf@ubuntu:~/work$ tar -zxvf openssl-1.1.1c.tar.gz
elf@ubuntu:~/work$ cd openssl-1.1.1c/
elf@ubuntu:~/work/openssl-1.1.1c$ ./config no-asm shared --prefix=/home/elf/work/openssl-1.1.1c/install
8 PLATFORM=linux-armv7
124 CNF_CFLAGS=-pthread
125 CNF_CXXFLAGS=-std=c++11 -pthread
90 #CROSS_COMPILE=
91 #CC=$(CROSS_COMPILE)gcc
92 #CXX=$(CROSS_COMPILE)g++
99 #MAKEDEPEND=$(CROSS_COMPILE)gcc
103 #AR=$(CROSS_COMPILE)ar
105 #RANLIB=$(CROSS_COMPILE)ranlib
106 #RC= $(CROSS_COMPILE)windres
elf@ubuntu:~/work/openssl-1.1.1c$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/openssl-1.1.1c$ make
elf@ubuntu:~/work/openssl-1.1.1c$ make install
elf@ubuntu:~/work/openssl-1.1.1c/install$ ls
bin include lib share ssl
elf@ubuntu:~/work/openssl-1.1.1c/install$ tar -cvjf openssl.tar.bz2 *
root@ELF1:~# cd /
root@ELF1:/# cp run/media/sda1/openssl.tar.bz2 .
root@ELF1:/# tar -xvf openssl.tar.bz2
elf@ubuntu:~/work$ tar xvf zlib-1.3.1.tar.gz
elf@ubuntu:~/work$ cd zlib-1.3.1
elf@ubuntu:~/work/zlib-1.3.1$ mkdir install
elf@ubuntu:~/work/zlib-1.3.1$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/zlib-1.3.1$ ./configure --prefix=$(pwd)/install
elf@ubuntu:~/work/zlib-1.3.1$ make
elf@ubuntu:~/work/zlib-1.3.1$ make install
elf@ubuntu:~/work/zlib-1.3.1/install$ ls
include lib share
elf@ubuntu:~/work/zlib-1.3.1/install$ tar -cvjf zlib.tar.bz2 *
root@ELF1:~# cd /
root@ELF1:/# cp run/media/sda1/zlib.tar.bz2 .
root@ELF1:/# tar -xvf zlib.tar.bz2
elf@ubuntu:~/work$ unzip libwebsockets-main.zip
elf@ubuntu:~/work$ cd libwebsockets-main/
elf@ubuntu:~/work/libwebsockets-main$ mkdir build
elf@ubuntu:~/work/libwebsockets-main$ mkdir install
elf@ubuntu:~/work/libwebsockets-main$ cd build
elf@ubuntu:~/work/libwebsockets-main/build$ vi ../CMakeLists.txt
#设置openssl的库头文件
set(OPENSSL_INCLUDE_DIR "/home/elf/work/openssl-1.1.1c/install/include/")
#设置openssl的库路径
set(OPENSSL_SSL_LIBRARY "/home/elf/work/openssl-1.1.1c/install/lib/libssl.so")
#设置openssl的工具库
set(OPENSSL_CRYPTO_LIBRARY "/home/elf/work/openssl-1.1.1c/install/lib/libcrypto.so")
#设置zlib的库头文件
set(ZLIB_INCLUDE_DIR "/home/elf/work/zlib-1.3.1/install/include/")
#设置openssl的库路径
set(ZLIB_LIBRARY "/home/elf/work/zlib-1.3.1/install/lib/libz.so")
#设置生成库的安装路径
SET(CMAKE_INSTALL_PREFIX "/home/elf/work/libwebsockets-main/install")
1011 if (LWS_HAVE_LIBCAP)
1012 set(LIBCAP_LIBRARIES /opt/fsl-imx-x11/4.1.15-2.0.0/sysroots/cortexa7hf-neon-poky-linux-gnueabi/lib/libcap.so)
1013 list(APPEND LIB_LIST_AT_END ${LIBCAP_LIBRARIES} )
1014 endif()
elf@ubuntu:~/work/libwebsockets-main/build$ . /opt/fsl-imx-x11/4.1.15-2.0.0/environment-setup-cortexa7hf-neon-poky-linux-gnueabi
elf@ubuntu:~/work/libwebsockets-main/build$ sudo apt-get update
elf@ubuntu:~/work/libwebsockets-main/build$ sudo apt-get install cmake
elf@ubuntu:~/work/libwebsockets-main/build$ cmake ..
elf@ubuntu:~/work/libwebsockets-main/build$ make
elf@ubuntu:~/work/libwebsockets-main/build$ make install
elf@ubuntu:~/work/libwebsockets-main/build$ cd ../install/
elf@ubuntu:~/work/libwebsockets-main/install$ ls
bin include lib share
elf@ubuntu:~/work/libwebsockets-main/install$ tar -cvjf libwebsockets.tar.bz2 *
root@ELF1:~# cd /
root@ELF1:/# cp run/media/sda1/libwebsockets.tar.bz2 .
root@ELF1:/# tar -xvf libwebsockets.tar.bz2
阅读全文