C语言 如何在 Linux 中安装 libwebsocket 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29470447/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:49:41  来源:igfitidea点击:

how to install libwebsocket library in linux?

cinstallationlibwebsockets

提问by Emb_user

I am trying to install the libwebsocket in my ubuntu .

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

so I downloaded the project https://github.com/warmcat/libwebsocketsunzipped it and I followed the installation instruction.

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

I type the command cmake FH and get the following messages.

我输入命令 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

I tried to compile a C program that uses libwebsocket.h, it tells me that it does not exist. Can any one show me the right way to install this lib. Thanks for any help .

我试图编译一个使用 libwebsocket.h 的 C 程序,它告诉我它不存在。任何人都可以告诉我安装这个库的正确方法。谢谢你的帮助 。

回答by WannaGetHigh

A simple way to install libwebsocket in Ubuntu is to use this command in a terminal:

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

sudo apt-get install libwebsockets-dev

须藤 apt-get 安装 libwebsockets-dev

This command will install the version 1.2.
The libwebsockets.hfile will be located at /usr/include/libwebsockets.h

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



An other way to have this library is to get the latest version (1.4at the moment) from GitHub. To do that open a Terminaland go in the directory you want to get the library (I will call it lib_dir).

拥有此库的另一种方法是从 GitHub获取最新版本(目前为1.4)。为此,请打开一个终端并进入您想要获取库的目录(我将称之为lib_dir)。

When you are in the lib_dirdirectory enter this command to get the code:

当您在lib_dir目录中时,输入此命令以获取代码:

git clone https://github.com/warmcat/libwebsockets.git

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

When the command finish you will find a directory named libwebsockets.
The libwebsockets.hfile will be located at lib_dir/libwebsockets/lib

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

If you need / want to build the library and install it in your system go in lib_dirthen enter the following commands:

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

sudo apt-get install libssl-dev
mkdir build
cd build
cmake ..
make
sudo make install
ldconfig

sudo apt-get install libssl-dev
mkdir build
cd build
cmake ..
make
sudo make install
ldconfig

This will install the library in /usr/local/include.
And to make sure of the version you just installed:

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

pkg-config --modversion libwebsockets

pkg-config --modversion libwebsockets

Finally you need to include in the compiler (include paths -I):

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

/usr/local/include

/usr/local/include

In the linker libraries (Libraries -l):

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

websockets

网络套接字

Finally (Library search path -L):

最后(库搜索路径 -L):

/usr/local/lib

/usr/本地/lib