-pthread in CLFAGS and LDFLAGS

James Browning jamesb192 at jamesb192.com
Sun Jul 19 15:57:50 UTC 2026


> On 07/19/2026 1:02 AM PDT Hal Murray via devel <devel at ntpsec.org> wrote:
> 
> I seem to remember that man pages told us to put -pthread into CFLAGS and
> LDFLAGs. I just looked around and can't find any like that.

Search engines should know everything.
They can be selectively friendly though.

> Is my memory busted or did somebody fix something?

People tend to fix things.

> Can somebody bring me up to date on this tangle?

Probably not.

The clang command line reference has "-pthread, -no-pthread
Support POSIX threads in generated code". man 1 gcc is more verbose with:

  -pthread
     Define additional macros required for using the POSIX threads
     library. You should use this option consistently for both
     compilation and linking. This option is supported on GNU/Linux
     targets, most other Unix derivatives, and also on x86 Cygwin and
     MinGW targets.

and...

  -pthread
     Link with the POSIX threads library. This option is supported on
     GNU/Linux targets, most other Unix derivatives, and also on x86
     Cygwin and MinGW targets. On some targets this option also sets
     flags for the preprocessor, so it should be used consistently for
     both compilation and linking.

as well as...

  -pthreads
    This is a synonym for -pthread.

Claim is -pthread is trivially harder to do, but defines _REENTRANT and somehow(?) adapts to platforms better. Ignore this bit It came from Google, and I didn't verify it.


More information about the devel mailing list