gnu-make

websocket projects recently reviewed: uWebSocket, which is used in Udacity self-driving car term2 projects. the other is libwebsocket, which is used in automotive message broker(amb).

gcc compiler options

gcc and make: a tutorial on how to compile, link and build c/c++ projects

-wall : print all warning messages 
-c : compile into object, by default the object has same name as the source file
-o : specify the output executable filename

headers(.h), static libs(.lib, .a) & shared libs(.dll, .so)

gcc by default, links to the shared libraries if available.

the compiler search “include-paths” for headers, which is specified via -L\ option or CPATH;

the linker search “library-paths” to link the program into an executable object, which is specified via -L\ or LIBRARY_PATH, in addition, need to specify the library name via -l

the system default “include-paths” can be found by “cpp -v”

gcc environment variables

PATH is used to search executable and run-time shared libs. (woo, this suppose to replace LD-LIBRARY-PATH)
CPATH is used to search “include-paths”, it’s searched after paths specified in -I<dir> options. C_INCLUDE_PATH & CPLUS_INCLUDE_PATH can be used to specify C & C++ headers
LIBRARY_PATH is used to search linking-time “library-paths”, it’s searched after paths specified in -L\ options. the standard directories is /usr/lib

Linux utils

1) readelf: read ELF

2) ldconfig : by default, read /etc/ls.so.conf, sets up the appropirate symbolic links in the dynamic link dir, and then write a cache to /etc/ld.so.cache, which then is used by other programs

3) ldd: to see recursive shared library dependencies

4) file: determine file type

5) nm: list symbol table of an object file, commonly-used to check if a particular func or variable is defined in an object file. “T” indicates it is defined; “U” means undefined, which should be resolved by the linker.

make & cmake

[gnu make] (https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents)

there are many best practical, e.g. effective cmake

build libuv

it’s built based on GNU autotools

sh autogen.sh  
"libtoolize: AC_CONFIG_MACRO_DIR([m4]) conflicts with ACLOCAL_AMFLAGS=-I m4"

fixing-solution, then make all & make install, so here is libuv.so, add the directory to \$LIBRARY_PATH in ~/.bashrc

build uWebSockets

it’s built based on gnu make. the tests command has dependents on libuv. since already added libuv directory to \$LIBRARY_PATH, run through. if else, errors output:

cannot find -luv
collect2: error: ld returned 1 exit status
Makefile:xx recipe for targe 'tests' failed    
make: *** [tests] Error 1 

try to run ./testsBin, get another error:

error while loading shared libraries: libuWS.so: cannot open shared object file: No such file or directory 

that’s run-time error, since libuWS.so is not included in \$PATH or speically for building/testing purpose, define $LD_LIBRARY_PATH.

build libwebsockets

it’s built based on cmake. there is some dependent, but should go through well.

beyond the note

when 2-months ago, looking at amb project, which has websocket plugin module, then find uWebSocket lib, during reading this tiny lib, where libuv APIs are highly-used, and soon found out libuv is actually the event-loop in nodejs. Woo, somehow they are related.

build tools are highly used in each project, but prior experience is more done by luck.