Various portability issues, mainly between linux/freebsd

prctl() / prctl.h

No prctl() in freebsd.

  • To set process title, use setproctitle()
  • For PR_SET_PTRACER, I'm not sure now.

malloc.h

Including malloc.h in freebsd leads to compile error. Use stdlib.h instead.

Anyway, in linux's malloc(3) manpage, it is said that you should include stdlib.h.

libdl

In linux, dlopen()/dlclose()/dlsym() are in libdl. In freebsd, they are in libc. So there is no point to link with libdl, and there is no libdl, anyway.

program_invocation_short_name

No such thing in bsd. Maybe you should use argv[0].

Include path / Lib path

freebsd installs all non-base softwares into /usr/local. So, the third party include files are in /usr/local/include, and third party lib files are in /usr/local/lib, and they are not in the default include/lib path, so you should include them with -I & -L.

The modern way is to use pkg-config. You may also use cmake's FindXXX.