生如夏花bld 2015-12-29 12:44 采纳率: 100%
浏览 7153
已采纳

windows下使用pthread.h库的问题

#include
#include
#include
#include
#include
pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t empty = PTHREAD_COND_INITIALIZER;
pthread_cond_t full = PTHREAD_COND_INITIALIZER;
char buf[256];

int main()
{
pthread_t t1,t2;
void * put_buf(void *);
void * get_buf(void *);
pthread_mutex_lock(&lock);
pthread_cond_signal(&empty);
pthread_create(&t1, NULL, put_buf, NULL);
pthread_create(&t2, NULL, get_buf, NULL);
pthread_join(t1, NULL);
pthread_join(t2, NULL);
return 0;
}
void *put_buf()
{
while (true)
{
pthread_cond_wait(&empty, &lock);
printf_s("empty flag is raised\n");
pthread_mutex_lock(&lock);
printf_s("input: \n");
gets_s(buf);
pthread_mutex_unlock(&lock);
pthread_cond_signal(&full);

}

}
void *get_buf(){
Sleep(2);
while (true)
{
pthread_cond_wait(&full, &lock);
printf_s("full flag is raised");
pthread_mutex_lock(&lock);
printf_s("output:\n");
pthread_cond_signal(&empty);
}
}


出现问题:错误 1 error LNK2019: 无法解析的外部符号 "void * __cdecl put_buf(void *)" (?put_buf@@YAPAXPAX@Z),该符号在函数 _main 中被引用 c:\Users\陌桑时代shine\documents\visual studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\源.obj ConsoleApplication2
错误 2 error LNK2019: 无法解析的外部符号 "void * __cdecl get_buf(void *)" (?get_buf@@YAPAXPAX@Z),该符号在函数 _main 中被引用 c:\Users\陌桑时代shine\documents\visual studio 2013\Projects\ConsoleApplication2\ConsoleApplication2\源.obj ConsoleApplication2

  • 写回答

2条回答 默认 最新

  • 一枪尽骚丶魂 2015-12-30 00:55
    关注

    额,你要不就把函数写在main函数前面,要不就写上该函数的声明!二选其一呀

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器