Search code examples
gccdebianc11threads.h

GCC undefined reference to thrd_create() in C11 mode after #include <threads.h> in Debian


I'm trying to compile a program that I've been able to compile on several other Debian environments with no issues using the C11 <threads.h> library on a relatively fresh install of Debian Bullseye with "gcc (Debian 10.2.1-6) 10.2.1 20210110" installed

with the command

gcc -o <progname> -O3 -Wall -Wextra -std=c11 -lpthread <sourcefile>

and I'm getting a string of linker errors in the form of undefined reference to 'mtx_unlock' as well as mtx_lock mtx_init thrd_create etc.

But I'm not getting an error saying the threads.h file is absent. I tried removing the -lpthread argument from the compilation command but this changed nothing.

What is going wrong?


Solution

  • The correct command line parameter seems to be -pthread without the l.