libwebsockets-2.1.0 编译过程

libwebsockets-2.1.0 编译过程

http://www.1314xuexi.com/forum.php?mod=viewthread&tid=792

user@ubuntu:~/work/libwebsockets-2.1.0/build$ cmake ..
-- CMAKE_TOOLCHAIN_FILE=''
fatal: not a git repository (or any of the parent directories): .git
Git commit hash: user@ubuntu-
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
zlib include dirs: /usr/include
zlib libraries: /usr/lib/x86_64-linux-gnu/libz.so
Compiling with SSL support
-- Found OpenSSL: /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib/libcrypto.so (found version "1.0.2j") 
OpenSSL include dir: /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/include
OpenSSL libraries: /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib/libssl.so;/home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib/libcrypto.so
-- Looking for openssl/ecdh.h
-- Looking for openssl/ecdh.h - not found
-- Looking for SSL_CTX_set1_param
CMake Warning at /home/user/work/libwebsockets-2.1.0/build/CMakeFiles/CMakeTmp/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target cmTC_2d127 because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.


-- Looking for SSL_CTX_set1_param - not found
-- Looking for X509_VERIFY_PARAM_set1_host
CMake Warning at /home/user/work/libwebsockets-2.1.0/build/CMakeFiles/CMakeTmp/CMakeLists.txt:14 (add_executable):
  Cannot generate a safe runtime search path for target cmTC_6877a because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.


-- Looking for X509_VERIFY_PARAM_set1_host - not found
Searching for OpenSSL executable and dlls
OpenSSL executable: /usr/bin/openssl
Generating SSL Certificates for the test-server...
SUCCESSFULLY generated SSL certificate
-- Looking for RPMTools... - rpmbuild NOT FOUND
---------------------------------------------------------------------
  Settings:  (For more help do cmake -LH <srcpath>)
---------------------------------------------------------------------
 LWS_WITH_STATIC = ON
 LWS_WITH_SHARED = ON
 LWS_WITH_SSL = ON (SSL Support)
 LWS_SSL_CLIENT_USE_OS_CA_CERTS = 1
 LWS_USE_WOLFSSL = OFF (wolfSSL/CyaSSL replacement for OpenSSL)
 LWS_WITHOUT_BUILTIN_SHA1 = OFF
 LWS_WITHOUT_BUILTIN_GETIFADDRS = OFF
 LWS_WITHOUT_CLIENT = OFF
 LWS_WITHOUT_SERVER = OFF
 LWS_LINK_TESTAPPS_DYNAMIC = OFF
 LWS_WITHOUT_TESTAPPS = OFF
 LWS_WITHOUT_TEST_SERVER = OFF
 LWS_WITHOUT_TEST_SERVER_EXTPOLL = OFF
 LWS_WITHOUT_TEST_PING = OFF
 LWS_WITHOUT_TEST_ECHO = OFF
 LWS_WITHOUT_TEST_CLIENT = OFF
 LWS_WITHOUT_TEST_FRAGGLE = OFF
 LWS_WITHOUT_EXTENSIONS = OFF
 LWS_WITH_LATENCY = OFF
 LWS_WITHOUT_DAEMONIZE = ON
 LWS_USE_LIBEV = 
 LWS_USE_LIBUV = 
 LWS_IPV6 = OFF
 LWS_UNIX_SOCK = OFF
 LWS_WITH_HTTP2 = OFF
 LWS_MBED3 = OFF
 LWS_SSL_SERVER_WITH_ECDH_CERT = OFF
 LWS_MAX_SMP = 32
 LWS_WITH_CGI = OFF
 LWS_HAVE_OPENSSL_ECDH_H = 
 LWS_HAVE_SSL_CTX_set1_param = 
 LWS_WITH_HTTP_PROXY = OFF
 LIBHUBBUB_LIBRARIES = 
 PLUGINS = 
 LWS_WITH_ACCESS_LOG = OFF
 LWS_WITH_SERVER_STATUS = OFF
 LWS_WITH_LEJP = OFF
 LWS_WITH_LEJP_CONF = OFF
 LWS_WITH_SMTP = OFF
 LWS_WITH_GENERIC_SESSIONS = OFF
 LWS_STATIC_PIC = OFF
---------------------------------------------------------------------
-- Configuring done
CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-server-extpoll
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1100 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-echo because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1245 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-server-pthreads
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1066 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-server because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1051 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-fraggle because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1232 (create_test_app)


CMake Warning at CMakeLists.txt:733 (add_library):
  Cannot generate a safe runtime search path for target websockets_shared
  because files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-fuzxy because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1058 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-ping because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1239 (create_test_app)


CMake Warning at CMakeLists.txt:1004 (add_executable):
  Cannot generate a safe runtime search path for target test-client because
  files in some directories may conflict with libraries in implicit
  directories:

    runtime library [libz.so.1] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
      /home/user/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

  Some of these libraries may not be found correctly.
Call Stack (most recent call first):
  CMakeLists.txt:1225 (create_test_app)


-- Generating done
-- Build files have been written to: /home/user/work/libwebsockets-2.1.0/build
user@ubuntu:~/work/libwebsockets-2.1.0/build$ 

make

buildroot目录下面
/home/user/NUC970_Buildroot-master/package/libwebsockets
在这里插入图片描述
修改 vi libwebsockets.mk 文件
在这里插入图片描述

在这里插入图片描述
修改之后
需要make clean
才会重新编译
make llibwebsockets-rebuild 不起作用

问题

如何添加自己的demo 测试程序
,参考一下 application
/home/user/NUC970_Buildroot-master/output/build/applications-1.0.0
/home/user/NUC970_Buildroot-master/package/applications
NUC980_SUBDIRS= demos/CAN
demos/alsa_audio
demos/cap
demos/crypto
demos/ebi
demos/etimer
demos/gpio
demos/irda
demos/rs485
demos/rtc
demos/sc
demos/spi
demos/uart
demos/wdt
demos/eth2uart
demos/wwdt

在这里插入图片描述
看一下 gpio的代码和编译方法
在这里插入图片描述

gcc test-server.c test-server-http.c test-server-dumb-increment.c test-server-mirror.c test-server-status.c test-server-echogen.c -lwebsockets -o lws_test_server -lssl -lcrypto -lz

-Llib目录

交叉编译

makefile

.SUFFIXES : .x .o .c .s

CC := arm-linux-gcc
STRIP := arm-linux-strip

TARGET = test-client
SRCS := test-client.c
LIBS = -lpthread -lc -lgcc
LIBS :=  -lwebsockets -lssl -lcrypto -ldl -lz
all: 
        $(CC)  $(SRCS) -o $(TARGET) $(LIBS)
        $(STRIP) $(TARGET) 

clean:
        rm -f *.o 
        rm -f *.x 
        rm -f *.flat
        rm -f *.map
        rm -f temp
        rm -f *.img
        rm -f $(TARGET) 
        rm -f *.gdb
        rm -f *.bak

这个makefile是可用的 ,交叉编译,不需要 -L
在这里插入图片描述

命令

#!/bin/sh
export PATH=/home/user/arm_work/host/usr/bin:$PATH

在这里插入图片描述
在这里插入图片描述

buildroot的时候,不要选择libuv libev

ubuntu 系统中不要安装 libssl 不要安装 libzip。
不然buildroot make的时候,有可能会出错。
lwsts[2438]: libev support not compiled in
lwsts[2438]: libuv support not compiled in

1

./libwebsockets-test-server --resource_path /home/mike/libwebsockets-2.1.0/build/share

111
Using resource path “/usr/local/share/libwebsockets-test-server”

Setting resource path to "/home/mike/libwebsockets-2.1.0/build/share"
lwsts[2465]: libwebsockets test server - license LGPL2.1+SLE
lwsts[2465]: (C) Copyright 2010-2016 Andy Green <andy@warmcat.com>
Using resource path "/home/mike/libwebsockets-2.1.0/build/share"
lwsts[2465]: Initial logging level 7
lwsts[2465]: Libwebsockets version: 2.1.0 mike@ubuntu-
lwsts[2465]: IPV6 not compiled in
lwsts[2465]: libev support not compiled in
lwsts[2465]: libuv support not compiled in
lwsts[2465]:  Threads: 1 each 1024 fds
lwsts[2465]:  mem: platform fd map:  8192 bytes
lwsts[2465]:  Compiled with OpenSSL support
lwsts[2465]:  SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
lwsts[2465]: Creating Vhost 'default' port 7681, 5 protocols, IPv6 off
lwsts[2465]:  Listening on port 7681
lwsts[2465]:  mem: per-conn:          512 bytes + protocol rx buf
lwsts[2465]:  canonical_hostname = ubuntu
lwsts[2465]: lws_protocol_init

在这里插入图片描述

mike@ubuntu:~/libwebsockets-2.1.0/build/bin$ ./libwebsockets-test-server --resource_path /home/mike/libwebsockets-2.1.0/build/share/libwebsockets-test-server 
Setting resource path to "/home/mike/libwebsockets-2.1.0/build/share/libwebsockets-test-server"
lwsts[2795]: libwebsockets test server - license LGPL2.1+SLE
lwsts[2795]: (C) Copyright 2010-2016 Andy Green <andy@warmcat.com>
Using resource path "/home/mike/libwebsockets-2.1.0/build/share/libwebsockets-test-server"
lwsts[2795]: Initial logging level 7
lwsts[2795]: Libwebsockets version: 2.1.0 mike@ubuntu-
lwsts[2795]: IPV6 not compiled in
lwsts[2795]: libev support not compiled in
lwsts[2795]: libuv support not compiled in
lwsts[2795]:  Threads: 1 each 1024 fds
lwsts[2795]:  mem: platform fd map:  8192 bytes
lwsts[2795]:  Compiled with OpenSSL support
lwsts[2795]:  SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT
lwsts[2795]: Creating Vhost 'default' port 7681, 5 protocols, IPv6 off
lwsts[2795]:  Listening on port 7681
lwsts[2795]:  mem: per-conn:          512 bytes + protocol rx buf
lwsts[2795]:  canonical_hostname = ubuntu
lwsts[2795]: lws_protocol_init
    get  = /xxx
    host: = 127.0.0.1:7681
    connection: = keep-alive, Upgrade
    upgrade: = websocket
    origin: = http://127.0.0.1:7681
    sec-websocket-extensions: = permessage-deflate
    sec-websocket-protocol: = dumb-increment-protocol
    http/1.1  = HTTP/1.1
    accept: = */*
    accept-encoding: = gzip, deflate
    accept-language: = en-US,en;q=0.5
    pragma: = no-cache
    cache-control: = no-cache
    cookie: = test=LWS_1618045848_272836_COOKIE
    sec-websocket-key: = w1BOJM5SVg9nYs6NEzo/9Q==
    sec-websocket-version: = 13
    user-agent: = Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
lwsts[2795]:  permessage-deflate requires the protocol (dumb-increment-protocol) to have an RX buffer >= 128
lwsts[2795]: ext permessage-deflate failed construction
lwsts[2795]: 0x55728ddabba0 new partial sent 30 from 178 total
lwsts[2795]:  Capping pmd rx to 128
lwsts[2795]: 0x55728ddabdd0 new partial sent 148 from 211 total
lwsts[2795]: cache_len 224
lwsts[2795]: 0x55728ddabdd0 new partial sent 148 from 186 total
    get  = /xxx
    host: = 127.0.0.1:7681
    connection: = keep-alive, Upgrade
    upgrade: = websocket
    origin: = http://127.0.0.1:7681
    sec-websocket-extensions: = permessage-deflate
    sec-websocket-protocol: = lws-mirror-protocol
    http/1.1  = HTTP/1.1
    accept: = */*
    accept-encoding: = gzip, deflate
    accept-language: = en-US,en;q=0.5
    pragma: = no-cache
    cache-control: = no-cache
    cookie: = test=LWS_1618045848_272836_COOKIE
    sec-websocket-key: = oIwsD1P+ATrqq4en76+MNA==
    sec-websocket-version: = 13
    user-agent: = Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0
lwsts[2795]:  Capping pmd rx to 128
lwsts[2795]: 0x55728de12710 new partial sent 148 from 220 total


222

 ./libwebsockets-test-server --resource_path /home/mike/libwebsockets-2.1.0/build/share/libwebsockets-test-server
参考

minimal-examples
三、其他的demo编译

  1. minimal-http-server-form-post

其他的demo位于minimal-examples,每一个demo里面都有CMakeList,可以执行cmake .&&make进行编译,以minimal-http-server-form-post为例:

由于我们修改了库的默认安装路径,所以必须修改CMakeList.txt,设置新的路径。

libwebsockets下载编译和测试
https://blog.csdn.net/u013752202/article/details/110637671

最简单完整的libwebsockets的例子
https://blog.csdn.net/dotphoenix/article/details/104837258

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples

在这里插入图片描述
在这里插入图片描述

一、参考网址:

libwebsockets官网: https://libwebsockets.org/

libwebsockets的API:https://libwebsockets.org/lws-api-doc-master/html/modules.html

                             https://libwebsockets.org/libwebsockets-api-doc.html

二、libwebsockets的安装

1、下载

git下载网址:https://github.com/hfeeki/libwebsockets

333

https://blog.csdn.net/xiyuan255/article/details/105840779

555

user@ubuntu:~/nuc980_iot/NUC970_Buildroot-master$ find . -name “libwebsockets.so”
./output/target/usr/lib/libwebsockets.so
./output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib/libwebsockets.so
./output/build/libwebsockets-v2.1.0/lib/libwebsockets.so

在这里插入图片描述

/home/user/nuc980_iot/NUC970_Buildroot-master/output/host/usr/arm-nuvoton-linux-uclibcgnueabi/sysroot/usr/lib

nuc980 libwebsockets-2.1.0 编译(可以使用)

/home/user/nuc980_iot/NUC970_Buildroot-master/package/libwebsockets/
libwebsockets.mk

在这里插入图片描述
其他的不要修改
make clean 然后make ,…
最终生成交叉编译工具链
/home/user/nuc980_iot/NUC970_Buildroot-master/output/host/
进入mike 用户
su mike
cd /home/mike/nuc980_work
source run_cmd.sh

run_cmd.sh 内容

#!/bin/sh
export PATH=/home/mike/nuc980_work/host/usr/bin:$PATH

/home/mike/nuc980_work/websocket/test-server/

在这里插入图片描述

Makefile

.SUFFIXES : .x .o .c .s

CC := arm-linux-gcc
STRIP := arm-linux-strip

TARGET = test-server
SRCS := test-server.c test-server-http.c test-server-dumb-increment.c test-server-mirror.c test-server-status.c test-server-echogen.c
LIBS = -lpthread -lc -lgcc
LIBS :=  -lwebsockets -lssl -lcrypto -ldl -lz
all: 
        $(CC)  $(SRCS) -o $(TARGET) $(LIBS)
        $(STRIP) $(TARGET) 

clean:
        rm -f *.o 
        rm -f *.x 
        rm -f *.flat
        rm -f *.map
        rm -f temp
        rm -f *.img
        rm -f $(TARGET) 
        rm -f *.gdb
        rm -f *.bak
~                                   

在目录
/home/mike/nuc980_work/websocket/test-server下面
修改test-server.c文件
在这里插入图片描述

直接make,会得到
在这里插入图片描述
通过scp 将生成的 test-server 发送到 板子/root/目录下面

还需要
在这里插入图片描述
在这里插入图片描述
share/libwebsockets-test-server的由来
是在ubuntu下面 编译
直接 mkdir build, cd build ,cmake … , make
然后再build目录下面会有share文件夹
在这里插入图片描述
这样就可以直接运行了

在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值