Issues with ld and static library "undefined reference to"

Does the following work?

cc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG tests/list_tests.c \
   -o tests/list_tests -Lbuild -llcthw

What this does is using the -l option to link against the library, and the -L option to specify an additional directory where the linker should look for libraries. The lib prefix and .a suffix must not be specified in the -l argument.

Note that if you also have a shared library (*.so) in the "build" directory, things get complicated. To keep things simple, you should either delete the "liblcthw.so" file and only keep "liblcthw.a", or try to link-in the static library by listing it as an input, just like you did originally, but specifying it after your source file:

cc -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG tests/list_tests.c \
   -o tests/list_tests build/liblcthw.a