libwebsockets Building on Ubuntu using libssl-dev and zlib

Overview

libwebsockets building on Ubuntu is tricky, and the official document is misleading, you need to install Zlib first and then install libssl-dev (not OpenSSL).

5 Steps to build libwebsockets on Ubuntu with Explanation

0. Install Zlib if you computer does not have it yet. CMake depends on this library for working correctly, otherwise, you will see an error when you try to do say "cmake .." in the following steps.

1. Install CMake 2.8 or greater: http://cmake.org/cmake/resources/software.html
   (Most Unix distributions comes with a packaged version also)
--> Remarks: You need to build and install CMake from scratch by execute: ./configure && make && make install

2. Install libssl-dev rather than OpenSSL.
--> Remarks: the official libwebsockets documents just say "Install OpenSSL" which is quite misleading and quite vague, if your computer only have openssl (e.g., you enter openssl in your command line, it prompts information), it is not the right one that cmake needs to build the configuration files for libwebsockets in ubuntue. 

The right thing you need is actually to install the development package, which is libssl-dev rather than OpenSSL, run the following in your command line:

sudo apt-get install libssl-dev 

3. Generate the build files (default is Make files):

	cd /path/to/src
	mkdir build
	cd build
	cmake ..

	(NOTE: The build/ directory can have any name and be located anywhere
	 on your filesystem, and that the argument ".." given to cmake is simply
	 the source directory of libwebsockets containing the CMakeLists.txt
	 project file. All examples in this file assumes you use "..")

	NOTE2
	A common option you may want to give is to set the install path, same
	as --prefix= with autotools.  It defaults to /usr/local.
	You can do this by, eg

	cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..

	NOTE3
	On machines that want libraries in lib64, you can also add the
	following to the cmake line

		-DLIB_SUFFIX=64

	NOTE4
	If you are building against a non-distro OpenSSL (eg, in order to get
	access to ALPN support only in newer OpenSSL versions) the nice way to
	express that in one cmake command is eg,

	cmake .. -DOPENSSL_ROOT_DIR=/usr/local/ssl \
		 -DCMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE=/usr/local/ssl \
		 -DLWS_WITH_HTTP2=1

	When you run the test apps using non-distro SSL, you have to force them
	to use your libs, not the distro ones

	LD_LIBRARY_PATH=/usr/local/ssl/lib libwebsockets-test-server --ssl

4. Finally you can build using the generated Makefile:

	make

Summary

libwebsockets building on Ubuntu is tricky, and the official document is misleading, you need to install Zlib first and then install libssl-dev (not OpenSSL).


(Please specify the source 烟客旅人 sigmainfy — http://www.sigmainfy.com as well as the original permalink

URL for any reprints, and please do not use it for commercial purpose)

Written on October 25, 2014