Immediate fixes after Emanuele's review.

Fixing segfault in gen app.
Adding header check for sys/bsd/queue.h, which can be found in Ubuntu™ in package libbsd-dev.
Moving stuff around with the linker, hoping this works out. Testing after this commit.