I want to include uWebSockets in a C++ project and I am unclear on how to do this. I've compiled projects with .so
dependencies, when it comes to projects listed on github I am still confused.
Specifically:
Apologies in advance if these questions seem obvious or silly, I come from a language with a package manager so this is rather new to me.
Update
Following the "Getting Started" instruction in the Github repository, upon cloning the repository, making sure that the dependencies are installed and running make
, the following output is observed:
dave@desktop:~/gitrepositories/uWebSockets$ make
make `(uname -s)`
make[1]: Entering directory '/home/dave/gitrepositories/uWebSockets'
g++ -std=c++11 -O3 -I src -shared -fPIC src/Extensions.cpp src/Group.cpp src/Networking.cpp src/Hub.cpp src/Node.cpp src/WebSocket.cpp src/HTTPSocket.cpp src/Socket.cpp src/Epoll.cpp -s -o libuWS.so
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/Group.h:4,
from src/Group.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Networking.cpp:1:0:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/Group.h:4,
from src/Hub.h:4,
from src/Hub.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/Node.h:4,
from src/Node.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/WebSocketProtocol.h:5:0,
from src/WebSocket.h:4,
from src/WebSocket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/HTTPSocket.h:4,
from src/HTTPSocket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
In file included from src/Socket.h:4:0,
from src/Socket.cpp:1:
src/Networking.h:7:30: fatal error: openssl/opensslv.h: No such file or directory
#include <openssl/opensslv.h>
^
compilation terminated.
Makefile:8: recipe for target 'Linux' failed
make[1]: *** [Linux] Error 1
make[1]: Leaving directory '/home/dave/gitrepositories/uWebSockets'
Makefile:6: recipe for target 'default' failed
make: *** [default] Error 2
Just to answer the questions:
Does the third-party repository need to be compiled prior to including it in my project?
Yes, you must compile the library before, because you cannot link your program without the library.
Where to store the library in the source code directory?
make install
will take care of this.
How to link the source code with third-party libraries?
You don't link the source code, but your object files together with the libraries to form an executable. This looks more or less like
g++ -o sample main.o second.o more.o -L/path/to/libs -luWS -lmorelibs
Are tools such as CMake needed?
Not in this case, uWebSockets
uses just make, nothing else.
The error messages are about missing header files. This means, you must install the appropriate developer packages for the prerequisites, namely openssl and zlib.
For Debian/Ubuntu this is done by
sudo apt-get install libssl-dev zlib1g-dev