How can I install the libwebsocket library in Ubuntu? - c

I am trying to install the libwebsocket in my ubuntu .
so I downloaded the project https://github.com/warmcat/libwebsockets
unzipped it and I followed the installation instruction.
I type the command cmake FH and get the following messages.
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 .

A simple way to install libwebsocket in Ubuntu is to use this command in a terminal:
sudo apt-get install libwebsockets-dev
This command will install the version 1.2.
The libwebsockets.h file will be located at /usr/include/libwebsockets.h
An other way to have this library is to get the latest version (1.4 at the moment) from GitHub. To do that open a Terminal and go in the directory you want to get the library (I will call it lib_dir).
When you are in the lib_dir directory enter this command to get the code:
git clone https://github.com/warmcat/libwebsockets.git
When the command finish you will find a directory named libwebsockets.
The libwebsockets.h file will be located at lib_dir/libwebsockets/lib
If you need / want to build the library and install it in your system go in lib_dir then enter the following commands:
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:
pkg-config --modversion libwebsockets
Finally you need to include in the compiler (include paths -I):
/usr/local/include
In the linker libraries (Libraries -l):
websockets
Finally (Library search path -L):
/usr/local/lib

Related

Installation of timescaledb failing

I've attempted to install timescaledb on Ubuntu 18.04 (32bit) with Postgresql 12 using:
https://docs.timescale.com/latest/getting-started/installation/ubuntu/installation-apt-ubuntu
When I run sudo apt install timescaledb-2-postgresql-12 I get the error:
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package timescaledb-2-postgresql-12
I then tried to go through and build the code locally (from the repository https://github.com/timescale/timescaledb) which was successful (on the make) but I was not able to see the "next steps" for what to do after the build. When I attempt to add the extension in the postgres.conf file by adding "shared_preload_libraries = 'timescaledb' " then restarting. On the restart I get the error
2021-02-22 07:24:28.711 EST [18311] syorke#postgres ERROR: could not open extension control file "/usr/share/postgresql/12/extension/timescaledb.control": No such file or directory
In the timescaledb.control is:
# timescaledb extension
comment = 'Enables scalable inserts and complex queries for time-series data'
default_version = '2.0.1'
module_pathname = '$libdir/timescaledb-2.0.1'
#extension cannot be relocatable once installed because it uses multiple schemas and that is forbidden by PG.
#(though this extension is relocatable during installation).
relocatable = false
My question is am I going about this correctly where the package was not found?
Should I replace the /usr/share/postgresql/12/extension/timescaledb.control with the timescaledb.control.in in the directory where I did my build for timescaledb?
In that control file from the build is:
# timescaledb extension
comment = 'Enables scalable inserts and complex queries for time-series data'
default_version = '#PROJECT_VERSION_MOD#'
module_pathname = '$libdir/timescaledb-#PROJECT_VERSION_MOD#'
#extension cannot be relocatable once installed because it uses multiple schemas and that is forbidden by PG.
#(though this extension is relocatable during installation).
relocatable = false
What would '#PROJECT_VERSION_MOD#' be replaced with and where is the $libdir set?
Thanks for any help.
Hi I just successuffly install on Ubuntu 20.04 using the script locate here
https://packagecloud.io/timescale/timescaledb/install
instead of doing the step 3 on the normal installation process
https://docs.timescale.com/install/latest/self-hosted/installation-debian/#installing-self-hosted-timescaledb-on-debian-based-systems
Then follow step 4 & 5 as on the documentation
As you have install from source maybe you will need to uninstall first

Error: chaincode install failed with status: 500

I have created a chaincode and I am trying to install it on the peer organization. I am able to package the chaincode on the peer organization but when it turns to install phase, I got error message:
Error: chaincode install failed with status: 500 - failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: docker build failed: docker image build failed: docker build failed: Error returned from build: 2
# github.com/Nik-U/pbc
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lpbc
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
I am using Nik-U's go wrapper of the PBC library Nik-U pbc. In his homepage, description shows:
This package must be compiled using cgo. It also requires the installation of GMP and PBC. During the build process, this package will attempt to include <gmp.h> and <pbc/pbc.h>, and then dynamically link to GMP and PBC.
Here's what I have tried:
I have manually configured the GMP and PBC under the Nik-U's directory and changed all the addresses of <gmp.h> and <pbc.h> to the right location.
I have tried to use command ln -s /usr/local/lib/libpbc.so libpbc.so and ln -s /usr/local/lib/libgmp.so to create link library files, but it shows the same error message.
As the Nik-U wrapper uses cgo, I changed the sentence in c.go file from #cgo LDFLAGS: -lpbc -lgmp to #cgo LDFLAGS: -L/usr/local/lib -lpbc -lgmp. Inside the /usr/loca/lib there are: libgmp.a libgmp.la libgmp.so libgmp.so.10 libgmp.so.10.4.1 libpbc.a libpbc.la libpbc.so libpbc.so.1 libpbc.so.1.0.0. This change did not work. I still got the same error message.
I copied all files of the directory /usr/local/lib to the same directory of the docker container using command docker cp **.so containerName:/usr/local/lib/. It does not work.
Here are what I doubt that may be the problem:
I am using go.mod file to manage all dependencies but the go.mod does not manage the original PBC library and GMP library. However, I do not know how to use go module to manage these two libraries (written in C?).
Nik-U's pbc wrapper has to link PBC and GMP libraries dynamically, which is why my efforts to manually configure and install them in the subdirectory, and change the include information such as from #include <pbc/pbc.h> to #include <pbc-0.5.14/include/pbc.h> of no use.
Can anybody help..
In hyperledger fabric, chaincode is executed in the form of sandbox based on virtual environment. In other words, it is not executed in the peer, but in a new docker container.
Even if you move the *.so file to the peer, it seems that a cannot find error has occurred because the newly created chaincode does not import it.
To solve this, two tasks are required.
1. import library to fabric-ccenv docker image
The go chaincode container of the fabric occurs in the image of fabric-ccenv. Based on the fabric-ccenv image, create a new image with your library embedded
FROM fabric-ccenv:<your_fabric_tag>
COPY <your_src_library_path> <your_target_library_path>
docker build -f <your_dockerfile> -t fabric-ccenv:<your_new_fabric_tag>
2. Change core.yaml of fabric-peer
You have to change the peer's configuration. That is, set the configuration for chaincode in core.yaml.
You can set information about fabric-ccenv in the builder item of chaincode. Change this value to the value of your image created in step 1 above.
chaincode:
id:
path:
name:
#builder: $(DOCKER_NS)/fabric-ccenv:$(TWO_DIGIT_VERSION)
builder: $(DOCKER_NS)/fabric-ccenv:<your_new_fabric_tag>
pull: false
golang:
runtime: $(DOCKER_NS)/fabric-baseos:$(TWO_DIGIT_VERSION)
dynamicLink: false

Compiling kernel module - what packages are required

Until now, When I compiled my kernel module, I installed: kernel-devel, kernel-headers.
Later on, I had to include kernel sources.
So now the packages I install in order to compile my kernel module are: kernel-devel, kernel-headers and kernel.src.rpm (kernel source).
Im in the process of creating a "build machine" that will check for Available latest kernel, download necessary packages and compile the kernel module for that kernel.
I dont want to install the package, just to download it, and copy the files to their location (download kernel.src.rpm, rpm2cpio, cpio, and copy to /lib/modules/kernel-X-Y/)
I noticed that if kernel src is installed, there is not need for kernel-headers.
kernel-devel is needed ??, I am not sure it is, when trying to install without kernel-devel, I get the following exception:
make[2]: Entering directory `/usr/src/kernels/3.10.0-693.el7.x86_64'
ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
What am I missing ? If i install kernel-devel, then i dont get this exception, I dont want to install kernel-devel.
Before you can run make to compile the kernel you need to run make oldconfig or copy a .config file over into the build tree. make oldconfig will then use the .config and update it to the newer kernel.
You also have other options:
a simple make help | grep -i config in the kernel source directory shows:
Configuration targets:
config - Update current config utilising a line-oriented program
nconfig - Update current config utilising a ncurses menu based
menuconfig - Update current config utilising a menu based program
xconfig - Update current config utilising a Qt based front-end
gconfig - Update current config utilising a GTK+ based front-end
oldconfig - Update current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
defconfig - New config with default from ARCH supplied defconfig
savedefconfig - Save current config as ./defconfig (minimal config)
allnoconfig - New config where all options are answered with no
allyesconfig - New config where all options are accepted with yes
allmodconfig - New config selecting modules when possible
alldefconfig - New config with all symbols set to default
randconfig - New config with random answer to all options
listnewconfig - List new options
olddefconfig - Same as silentoldconfig but sets new symbols to their
kvmconfig - Enable additional options for kvm guest kernel support
xenconfig - Enable additional options for xen dom0 and guest kernel support
tinyconfig - Configure the tiniest possible kernel
kselftest-merge - Merge all the config dependencies of kselftest to existing
.config.
configuration. This is e.g. useful to build with nit-picking config.
i386_defconfig - Build for i386
x86_64_defconfig - Build for x86_64
make O=dir [targets] Locate all output files in "dir", including .config

Ubuntu - Right protobuf paths for ./configure command

I am following Google official documentation for GAE (Google app engine) installation.
Look at this part (relative to gae php extension): https://github.com/GoogleCloudPlatform/appengine-php-extension
./configure --enable-gae --with-protobuf_inc=<include_path> --with-protobuf_lib=<lib_path>
The documentation says:
Set <include_path> and <lib_path> to where you have installed the protobuf headers and libraries in the previous step.
I always get an error in the terminal when I run the ./configure command, because I don't know which are the right protobuf paths.
P.s.
When installing Protobuf I followed this documentation:
https://github.com/google/protobuf/blob/master/src/README.md
My /home/Experiments folder contains 3 folders:
php-src, appengine-php-extension, protobuf.
The protobuf folder is where I have "git cloned" protobuf to install it.
If you follow the instructions under Building in the linked repository for the App Engine PHP Runtime, you'll find that in step 2, you choose an output directory when generating C++ source and header files for remote_api.proto and urlfetch_service.proto. That folder would be the correct one to supply via cmd args.

CMake : multiple subprojects using the same static library

I'm using cmake to compile one of my work projets, here is the deal
-
client/
CMakeLists.txt
server/
CMakeLists.txt
libs/
libstuff/
CMakeLists.txt
CMakeLists.txt
So i want to be able to compile each subproject individually, and build both the client and the server from the root folder.
Let's say the client and the server need libstuff.
I tried to use "add_subdirectory" with the path of the lib in both client and server CMakeLists.txt, it works when you compile the server or the client, but if you try to run both from the root directory :
CMake Error at common/libplugin/CMakeLists.txt:33 (ADD_LIBRARY):
add_library cannot create target "plugin" because another target with the
same name already exists. The existing target is a static library created
in source directory "/home/adrien/git/r-type/common/libplugin". See
documentation for policy CMP0002 for more details.
So i'm kind of new w/ cmake and i'm not sure what i should do, should i use add_dependencies?
Thanks for your help,
A simple solution is to guard the add_subdirectory calls in both the client and the server CMake list file with an if using a TARGET conditional, i.e.:
if (NOT TARGET plugin)
add_subdirectory("${CMAKE_SOURCE_DIR}/common/libplugin")
endif()
This prevents the libplugin sub-directory from being added more than once.
I would suggest putting three add_subdirectory calls in your root CMakeLists.txt. libstuff first, then client and server....
Setup the Stuff project as if it is standalone, but add variables to the cmake cache such that it can be "imported" by other projects. Then, in client and server, you can refer to the Stuff project... using ordinary call include_directories and target_link_libraries.
E.g. in libstuff...
# libstuff CMakeLists
project( Stuff )
# ... whatever you need here: collect source files, ...
add_library( LibStuff ${Stuff_Sources} )
# Then, define a very useful variables which gets exported to the cmakecache and can be
# used by other cmakelists
set( STUFF_INCLUDE_DIRS ${Stuff_SOURCE_DIR} CACHE STRING "Include-dir for Stuff." FORCE )
And then in Client (and similarly in Server)
# client CMakeLists
project( Client )
# refer to Stuff-includes here...
include_directories( ${STUFF_INCLUDE_DIRS} )
add_executable( Client client.h client.cpp main.cpp ) #
target_link_libraries( Client LibStuff )
You can then "compile" only the Client directory, by stepping into the Client dir and running make or msbuild there. Alternatively, you could add a cmake-flag to the root-cmakelistt which is used to filter between Client, Server or both...

Resources