- 论坛徽章:
- 0
|
做一个小程序测试时用到sched_setaffinity,结果最后链接出问题,后来发现在/usr/include/sched.h中:
#ifdef __USE_GNU
/* Access macros for `cpu_set'. */
#define CPU_SETSIZE __CPU_SETSIZE
#define CPU_SET(cpu, cpusetp) __CPU_SET (cpu, cpusetp)
#define CPU_CLR(cpu, cpusetp) __CPU_CLR (cpu, cpusetp)
#define CPU_ISSET(cpu, cpusetp) __CPU_ISSET (cpu, cpusetp)
#define CPU_ZERO(cpusetp) __CPU_ZERO (cpusetp)
/* Set the CPU affinity for a task */
extern int sched_setaffinity (__pid_t __pid, size_t __cpusetsize,
__const cpu_set_t *__cpuset) __THROW;
/* Get the CPU affinity for a task */
extern int sched_getaffinity (__pid_t __pid, size_t __cpusetsize,
cpu_set_t *__cpuset) __THROW;
#endif
而__USE_GNU在<features.h>中先undef,然后根据另一个宏来决定是否定义:
#ifdef _GNU_SOURCE
# define __USE_GNU 1
#endif
这一头文件使用其它头文件时会被引用起来。但_GNU_SOURCE不知道是啥时候定义的,感觉是应该编译时支持
GCC扩展(缺省应该就是)就自动定义的,但实际测试却不是这样的;加上-std=gnu89或-std=gnu99都不行。
现在是编译时在命令行直接加上-D_GNU_SOURCE来搞定问题的,但感觉很奇怪。 |
|