Live & Learn
分类: LINUX
2019-02-14 14:24:30
//编译libwebsockets
//==========ubuntu下编译安装libwebsockets===================
1.GitHub地址:
2.确保cmake、openssl安装成功
源码安装或是apt-get安装都可以。
我这里选择apt-get安装,方便一些。
#sudo apt-get install cmake
#sudo apt-get install openssl
#sudo apt-get install libssl-dev123
注意:apt-get安装openssl时还需要安装libssl-dev,否则会在后面找不到头文件,编译libwebsockets时提示找不到ssl.h
等,此外,还需要注意openssl的版本好像要大于1.0.0,libwebsockets使用的openssl的版本有最低要求,具体参见官网说明
3.Ubuntu下下载、编译及安装
准备好环境后就可以下载、编译及安装libwebsockets了:
#
git clone
#cd libwebsockets
#mkdir build
#cd build
#cmake ..
#make
#sudo make install
4.测试
安装完成后,开启服务。
# ./libwebsockets-test-server
[2019/02/13 22:03:14:8751] NOTICE: libwebsockets test server - license LGPL2.1+SLE
[2019/02/13 22:03:14:8752] NOTICE: (C) Copyright 2010-2018 Andy Green <>
Using resource path "/usr/local/share/libwebsockets-test-server"
5.ubuntu客户端连接服务器
# ./libwebsockets-test-client 127.0.0.1
[2019/02/13 22:04:36:3907] NOTICE: libwebsockets test client - license LGPL2.1+SLE
[2019/02/13 22:04:36:3907] NOTICE: (C) Copyright 2010-2018 Andy Green <>
[2019/02/13 22:04:36:3907] NOTICE: SSL disabled
[2019/02/13 22:04:36:3907] NOTICE: Cert must validate correctly (use -s to allow selfsigned)
[2019/02/13 22:04:36:3907] NOTICE: Requiring peer cert hostname matches
[2019/02/13 22:04:36:3935] NOTICE: created client ssl context for default
[2019/02/13 22:04:36:3939] NOTICE: using mode (ws)
[2019/02/13 22:04:36:3940] NOTICE: dumb: connecting
[2019/02/13 22:04:36:3943] NOTICE: mirror: connecting
[2019/02/13 22:04:36:3949] NOTICE: mirror: LWS_CALLBACK_CLIENT_ESTABLISHED
[2019/02/13 22:04:36:3950] NOTICE: opened mirror connection with 44216 lifetime
//==========交叉编译安装libwebsockets===================
1、交叉编译openssl
$ 执行./config no-asm -shared --prefix=/usr/local/ssl-arm/ 产生Makefile
$ 修改Makefile CC= arm-hisiv500-linux-gcc 去除编译和链接选项 -m64
$ 执行make && make install 编译和安装openssl库
2、交叉编译zlib
$ tar jvxf zlib-1.2.3.tar.bz2
$ cd zlib-1.2.3/
$ export CC=arm-linux-gcc //它的configure不支持用CC变量来指定交叉工具链
$ ./configure --prefix=/usr/local/zlib-arm/
$ make && make install
3.交叉编译libwebsocket
$cd libwebsockets-master
$mkdir build
$cd build
$cmake .. \
-DCMAKE_INSTALL_PREFIX=/usr/local/libwebs-arm \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_C_COMPILER=arm-linux-gcc \
-DCMAKE_CXX_COMPILER=arm-linux-g++ \
-DZLIB_INCLUDE_DIR=/usr/local/zlib-arm/include \
-DZLIB_LIBRARY="/usr/local/zlib-arm/lib/libz.so" \
-DLWS_OPENSSL_INCLUDE_DIRS=/usr/local/ssl-arm/include/ \
-DLWS_OPENSSL_LIBRARIES="/usr/local/ssl-arm/lib/libssl.so;/usr/local/ssl-arm/lib/libcrypto.so"
$make && make install
4、安装到交叉环境中
拷贝libwebs-arm到开发板中
5、测试交叉环境
执行libwes-arm中的bin文件.
/mnt/libwebs-arm/bin # ./libwebsockets-test-server -h
Usage: test-server [--port=
] [--ssl] [-d
//测试服务器
#./libwebsockets-test-server
//测试客户端
#./libwebsockets-test-client 192.168.101.168