Actually, the problem appears to be with ld rather than g++. This thread gave me a hint: https://forums.freebsd.org/threads/5799/
"ldl is libdl. It is a linuxism. FreeBSD does not have a libdl. The same functionality that is in linux's libdl is provided in FreeBSD's libc. So you should be able to simply remove -ldl from CFLAGS and try compile." I know I should edit build.gradle further so that ldl is not included in CFLAGS when compiling on OpenBSD, but I have not worked with gradle build files and would very much appreciate it if you guys could help me out in crafting the proper target definitions for OpenBSD. - Jyri -- Turvamies IT Security Services