LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 643|回复: 1

为什么我不能使用线程函数呀?

[复制链接]
发表于 2004-6-3 00:13:59 | 显示全部楼层 |阅读模式
我用的是Red Hat EnterPrise Linux ES(2.4.21-9.EL) .
我用以下代码测试.
int main()
{
  printf("OSIX version is set to %ld\n", _POSIX_VERSION);
  if (_POSIX_VERSION < 199506L)
  {
    if (_POSIX_C_SOURCE >= 199506L)
    {
        printf("Sorry, your system does not support POSIX1003.1c threads\n");
    }
    else
    {
          printf("Try again with -D_POSIX_C_SOURCE = 199506L\n");
    }
  }
  else
  {
            printf("Your system supports POSIX1003.1c threads.\n");
        #ifdef _POSIX_THREAD_RPIORITY_SCHEDULING
          printf("including support for priority scheduling\n");
        #else
          printf("But does not support priority scheduling\n");
        #endif
  }
  exit(EXIT_SUCCESS);
}
输出结果如下:  POSIX version is set to 199506
Your system supports POSIX1003.1c threads.
But does not support priority scheduling
我的一个程序名为thread1.c  头文件包函了 pthread.h
我使用 gcc -D_REENTRANT thread1.c -o thread
输出结果如下:
/tmp/ccAofBGq.o(.text+0x21): In function `main':
: undefined reference to `pthread_create'
为什么会这样呢? 谁能帮我一下吗?
发表于 2004-6-3 09:36:01 | 显示全部楼层
gcc -D_REENTRANT thread1.c -o thread -lpthread

嗯,以后有问题最好先搜索一下 :)
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表