求助,已经加上-lpthread,还是找不到pthread_setaffinity_np

xmmx123 2007-02-08 11:59:25


gcc 1.c -o test -lm -lpthread

提示 undefined reference to `pthread_setaffinity_np'

但是像pthread_create 什么的却能正常编译通过

环境:

2.6 linux
getconf GNU_LIBPTHREAD_VERSION nptl 0.61
...全文
2522 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmz7573 2012-03-25
  • 打赏
  • 举报
回复
我发现Centos4.6和Centos5.2中/usr/include/pthread.h中没有pthread_setaffinity_np()这个函数,而在Centos5.6中/usr/include/pthread.h有pthread_setaffinity_np(),现在我要在Centos4.6中编译通过,我该怎样加入宏?


[Quote=引用 3 楼 x86 的回复:]

头文件里面是这样定义的:
#ifdef __USE_GNU
/* Yield the processor to another thread or process.
This function is similar to the POSIX `sched_yield ' function but
……
[/Quote]
lmz7573 2012-03-25
  • 打赏
  • 举报
回复
我发现Centos4.6和Centos5.2中/usr/include/pthread.h中没有pthread_setaffinity_np()这个函数,而在Centos5.6中/usr/include/pthread.h有pthread_setaffinity_np(),现在我要在Centos4.6中编译通过,我该怎样加入宏?
leduo 2007-03-25
  • 打赏
  • 举报
回复
你是不是参数类型不匹配呢?
xmmx123 2007-03-25
  • 打赏
  • 举报
回复
d
xmmx123 2007-02-11
  • 打赏
  • 举报
回复
顶一下

谁能帮忙一下呢?

谢谢了
x86 2007-02-09
  • 打赏
  • 举报
回复
头文件里面是这样定义的:
#ifdef __USE_GNU
/* Yield the processor to another thread or process.
This function is similar to the POSIX `sched_yield' function but
might be differently implemented in the case of a m-on-n thread
implementation. */
extern int pthread_yield (void) __THROW;


/* Limit specified thread TH to run only on the processors represented
in CPUSET. */
extern int pthread_setaffinity_np (pthread_t __th, size_t __cpusetsize,
__const cpu_set_t *__cpuset) __THROW;

/* Get bit set in CPUSET representing the processors TH can run on. */
extern int pthread_getaffinity_np (pthread_t __th, size_t __cpusetsize,
cpu_set_t *__cpuset) __THROW;
#endif

所以你需要定义__USE_GNU宏,可以在源文件里定义:
#define __USE_GNU
也可以加在编译参数里:
gcc -D__USE_GNU -o test test.c -lpthread
xmmx123 2007-02-09
  • 打赏
  • 举报
回复
所以你需要定义__USE_GNU宏,可以在源文件里定义:
#define __USE_GNU
也可以加在编译参数里:
gcc -D__USE_GNU -o test test.c -lpthread
------------------

我已经 在文件中

#define __USE_GNU
#include<pthread.h>
但是还是找不到

真是奇怪 啊



pthread_setaffinity_np
不是谁都支持

-------------
怎么说
Arthur_ 2007-02-09
  • 打赏
  • 举报
回复
pthread_setaffinity_np
不是谁都支持
xmmx123 2007-02-09
  • 打赏
  • 举报
回复
设置程序运行在哪个cpu上

里边调用的是sched_setaffinity
awjx 2007-02-09
  • 打赏
  • 举报
回复
pthread_setaffinity_np是什么啊?好像是不是lpthread里面的。

23,124

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧