LinuxSir.cn,穿越时空的Linuxsir!

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

pthread.h 编译问题?

[复制链接]
发表于 2006-10-12 13:27:05 | 显示全部楼层 |阅读模式
这是APUE 上的一个关于pthread的程序.可是我编译时gcc提示
phtread_create 未定义,可是pthread.h加了的吗!?也有 /usr/include/pthread.h 这个头文件!请路过的朋友能看看呀!3q!

#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

pthread_t ntid;
static void printids(char *);
static void *thr_fn(void *);

int
main(void)
{
  int err;
  err = pthread_create (&ntid, NULL,thr_fn, NULL);
  if (err != 0)
    printf ("ptherd_create error \n");
  printids ("main thread: ");
  sleep (1);
  exit (0);
}

void printids(char *s)
{
  pid_t         pid;
  pthread_t     tid;
  pid = getpid ();
  tid = pthread_self ();
  printf ("%s pid %u  tid %u  (0x%x)\n",
          s, (unsigned int)pid, (unsigned int)tid, (unsigned int)tid);
}

void *thr_fn(void *arg)
{
  printids ("new thread: ");
  return ((void *)0);
}
发表于 2006-10-12 14:00:20 | 显示全部楼层
-lpthread
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

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