FreeBSD Porter's Handbook
Prev | Chapter 12 Dos and Don'ts | Next

# 12.11 Threading Libraries

The threading library must be linked to the binaries using a special linker flag `-pthread` on FreeBSD. If a port insists on linking `-lpthread` or `-lc_r` directly, patch it to use `PTHREAD_LIBS` variable provided by the ports framework. This variable usually has the value of `-pthread`, but on certain architectures and FreeBSD versions it can have different values, so do not just hardcode `-pthread` into patches and always use `PTHREAD_LIBS`.

> Note: If building the port errors out with `unrecognized option '-pthread'` when setting `PTHREAD_LIBS`, it may be desirable to use `gcc` as linker by setting `CONFIGURE_ENV` to `LD=${CC}`. The `-pthread` option is not supported by `ld` directly.

Prev | Home | Next
Respect `CFLAGS` | Up | Feedback

For questions about the FreeBSD ports system, e-mail <ports@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.