Undefined reference to `CPU_ZERO '

I have included:

#include <sched.h> #define _GNU_SOURCE 

then in my code I wrote (brief mention):

 cpu_set_t set; CPU_ZERO( &set ); CPU_SET( proc_num, &set ); if (sched_setaffinity( gettid(), sizeof( cpu_set_t ), &set )) { perror( "sched_setaffinity" ); return NULL; } 

But when I compile, I find

 undefined reference to 'CPU_ZERO' undefined reference to 'CPU_SET' 

Please, help...

+7
c linux pthreads
source share
1 answer

You need to post

 #define _GNU_SOURCE 

not less than

 #include <sched.h> 

because it determines what the file should contain.

More about this on the corresponding man page here .


Update

To make sure everything is installed as needed, put #define at the beginning of the source files, that is, before all #include s.

Alternatively, you can pass #define on the GCC command line with the option

 -D_GNU_SOURCE 
+14
source share

All Articles