Linking pthread/dl errors when building netgen program

Hi, I have tried building the minimal netgen test program below

#include <cstddef> namespace nglib { #include <nglib.h> } int main() { nglib::Ng_Init(); nglib::Ng_Exit(); }

using the command

g++ src/main.cpp -L/opt/netgen/lib -I/opt/netgen/include -lnglib -ldl -lpthread -pthread

but linking always fails finding pthread_create and dladdr as

/opt/netgen/lib/libinterface.so: undefined reference to `pthread_create' /opt/netgen/lib/libngcore.so: undefined reference to `dladdr' collect2: error: ld returned 1 exit status
so I’m assuming there is some issue linking “dl” and “pthread” but no matter how or in which position I put the flags helps. Any ideas what could be the issue here? (Working in Ubuntu Linux 18.10 and gcc 7.5)