如何在 Ubuntu 中安装 libwebsocket 库?

Posted

技术标签:

【中文标题】如何在 Ubuntu 中安装 libwebsocket 库?【英文标题】:How can I install the libwebsocket library in Ubuntu? 【发布时间】:2015-04-06 11:33:08 【问题描述】:

我正在尝试在我的 ubuntu 中安装 libwebsocket。

所以我下载了项目https://github.com/warmcat/libwebsockets 解压后按照安装说明进行操作。

我键入命令 cmake FH 并收到以下消息。

  You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:State or Province Name (full name) [Some-State]:Locality Name (eg, city) []:Organization Name (eg, company) [Internet Widgits Pty Ltd]:Organizational Unit Name (eg, section) []:Common Name (e.g. server FQDN or YOUR name) []:Email Address []:SUCCSESFULLY generated SSL certificate
Generating API documentation
-- Looking for RPMTools... - rpmbuild NOT FOUND
---------------------------------------------------------------------
  Settings:  (For more help do cmake -LH <srcpath>
---------------------------------------------------------------------
 LWS_WITH_SSL = ON  (SSL Support)
 LWS_SSL_CLIENT_USE_OS_CA_CERTS = 1
 LWS_USE_CYASSL = OFF (CyaSSL replacement for OpenSSL)
 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_CLIENT = OFF
 LWS_WITHOUT_TEST_FRAGGLE = OFF
 LWS_WITHOUT_DEBUG = OFF
 LWS_WITHOUT_EXTENSIONS = OFF
 LWS_WITH_LATENCY = OFF
 LWS_WITHOUT_DAEMONIZE = OFF
 LWS_USE_LIBEV = 
 LWS_IPV6 = OFF
 LWS_WITH_HTTP2 = OFF
---------------------------------------------------------------------
-- Configuring done
-- Generating done
-- Build files have been written to: /home/maroua/libwebsocket/libwebsockets-master
-- Cache values
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
CMAKE_BUILD_TYPE:STRING=

// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local

// Libwebsockets include directories
LIBWEBSOCKETS_INCLUDE_DIRS:PATH=/home/maroua/libwebsocket/libwebsockets-master/lib;/home/maroua/libwebsocket/libwebsockets-master

// Libwebsocket libraries
LIBWEBSOCKETS_LIBRARIES:STRING=websocket;websockets_shared

// Libwebsocket shared library
LIBWEBSOCKETS_LIBRARIES_SHARED:STRING=websockets_shared

// Libwebsocket static library
LIBWEBSOCKETS_LIBRARIES_STATIC:STRING=websocket

// Path to the CyaSSL include directory
LWS_CYASSL_INCLUDE_DIRS:PATH=

// Path to the CyaSSL library
LWS_CYASSL_LIB:PATH=

// Installation directory for executables
LWS_INSTALL_BIN_DIR:PATH=bin

// Installation directory for CMake files
LWS_INSTALL_CMAKE_DIR:PATH=lib/cmake/libwebsockets

// Installation directory for example files
LWS_INSTALL_EXAMPLES_DIR:PATH=bin

// Installation directory for header files
LWS_INSTALL_INCLUDE_DIR:PATH=include

// Installation directory for libraries
LWS_INSTALL_LIB_DIR:PATH=lib

// Compile with support for ipv6
LWS_IPV6:BOOL=OFF

// Link the test apps to the shared version of the library. Default is to link statically
LWS_LINK_TESTAPPS_DYNAMIC:BOOL=OFF

// Server SSL certificate directory
LWS_OPENSSL_CLIENT_CERTS:PATH=../share

// SSL support should make use of OS installed CA root certs
LWS_SSL_CLIENT_USE_OS_CA_CERTS:BOOL=ON

// Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS
LWS_USE_CYASSL:BOOL=OFF

// Search the system for ZLib instead of using the included one (on Windows)
LWS_USE_EXTERNAL_ZLIB:BOOL=OFF

// Don't use BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... Default is your libc provides it. On some systems such as uclibc it doesn't exist.
LWS_WITHOUT_BUILTIN_GETIFADDRS:BOOL=OFF

// Don't build the client part of the library
LWS_WITHOUT_CLIENT:BOOL=OFF

// Don't build the daemonization api
LWS_WITHOUT_DAEMONIZE:BOOL=OFF

// Don't compile debug related code
LWS_WITHOUT_DEBUG:BOOL=OFF

// Don't compile with extensions
LWS_WITHOUT_EXTENSIONS:BOOL=OFF

// Don't build the server part of the library
LWS_WITHOUT_SERVER:BOOL=OFF

// Don't build the libwebsocket-test-apps
LWS_WITHOUT_TESTAPPS:BOOL=OFF

// Don't build the client test application
LWS_WITHOUT_TEST_CLIENT:BOOL=OFF

// Don't build the ping test application
LWS_WITHOUT_TEST_FRAGGLE:BOOL=OFF

// Don't build the ping test application
LWS_WITHOUT_TEST_PING:BOOL=OFF

// Don't build the test server
LWS_WITHOUT_TEST_SERVER:BOOL=OFF

// Don't build the test server version that uses external poll
LWS_WITHOUT_TEST_SERVER_EXTPOLL:BOOL=OFF

// Compile with support for http2
LWS_WITH_HTTP2:BOOL=OFF

// Build latency measuring code into the library
LWS_WITH_LATENCY:BOOL=OFF

// Compile with support for libev
LWS_WITH_LIBEV:BOOL=OFF

// Include SSL support (default OpenSSL, CyaSSL if LWS_USE_CYASSL is set)
LWS_WITH_SSL:BOOL=ON

// The RPM builder tool
RPMTools_RPMBUILD_EXECUTABLE:FILEPATH=RPMTools_RPMBUILD_EXECUTABLE-NOTFOUND

我试图编译一个使用 libwebsocket.h 的 C 程序,它告诉我它不存在。 谁能告诉我安装这个库的正确方法。 感谢您的帮助。

【问题讨论】:

厌倦了这些巨魔 -1 而没有试图提供帮助。这是一个合法的问题,得到了有用的答案。请为合法问题 +1 @joël 这可能是因为 libwebsockets 有一个相当详细的 build.readme。但我同意,如果因为这个原因做 -1,应该在评论中说明这一点。 (github.com/warmcat/libwebsockets/blob/master/README.build.md) 【参考方案1】:

在 Ubuntu 中安装 libwebsocket 的一种简单方法是在终端中使用此命令:

sudo apt-get install libwebsockets-dev

此命令将安装版本 1.2libwebsockets.h 文件将位于 /usr/include/libwebsockets.h


获取此库的另一种方法是从 GitHub 获取最新版本(目前为1.4)。为此,请打开 Terminal 并进入您想要获取库的目录(我将其命名为 lib_dir)。

当你在lib_dir目录下输入这个命令获取代码:

git 克隆https://github.com/warmcat/libwebsockets.git

命令完成后,您将找到一个名为 libwebsockets 的目录。libwebsockets.h 文件将位于 lib_dir/libwebsockets/lib

如果您需要/想要构建库并将其安装到您的系统中,请进入lib_dir,然后输入以下命令:

sudo apt-get install libssl-dev mkdir 构建 光盘构建 cmake .. 制作 须藤制作安装 配置文件

这将在/usr/local/include 中安装库。 并确保您刚刚安装的版本:

pkg-config --modversion libwebsockets

最后你需要在编译器中包含(包含路径-I):

/usr/local/包括

在链接器库(Libraries -l)中:

网络套接字

最后(图书馆搜索路径-L):

/usr/local/lib

【讨论】:

完美运行 :) 一个问题:libssl-dev 是做什么用的? Ubuntu 15.04 预装了这个,所以没问题,我只是好奇! @NicolaiAntonLynnerup 很高兴它帮助了你 :) 它是一个包,是 openssl 项目实现 ssl 和 tls 加密协议的一部分,用于通过 Internet 进行安全通信。 有人能解释一下最后三个步骤吗? (linux新手) @KenVernaillen 最后三个步骤在编译代码时用作参数。去检查GCC and make。它解释了如何编译以及如何设置参数。

以上是关于如何在 Ubuntu 中安装 libwebsocket 库?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Ubuntu 中安装 libwebsocket 库?

如何在 ubuntu 中安装 bluejeans?

如何在ubuntu中安装php

如何在 WSL 中安装多个单独的 Ubuntu 实例? [关闭]

如何在Ubuntu中安装Spring Boot CLI?

如何在ubuntu系统中安装搜狗输入法