gpt4 book ai didi

c - 未检测到多线程库

转载 作者:太空宇宙 更新时间:2023-11-04 04:53:05 25 4
gpt4 key购买 nike

这是我编写的一个简单代码,用于在 Eclipse 中学习在 Windows 7 操作系统上进行多线程编程。

pthread_mutex_t double_release_001_glb_mutex_;
pthread_mutex_t * double_release_001_glb_mutex = & double_release_001_glb_mutex_;

void double_release_001_glb_mutex_lock () {}
void double_release_001_glb_mutex_unlock () {}

int double_release_001_glb_data = 0;

void * double_release_001_tsk_001 (void * pram)
{

pthread_mutex_lock (double_release_001_glb_mutex);
double_release_001_glb_data = (double_release_001_glb_data% 100) + 1;

pthread_mutex_unlock (double_release_001_glb_mutex);
return NULL;
}

void double_release_001 ()
{
pthread_t tid1;
pthread_mutex_init (double_release_001_glb_mutex, NULL);
pthread_create (& tid1, NULL, double_release_001_tsk_001, NULL);
pthread_join (tid1, NULL);
pthread_mutex_destroy (double_release_001_glb_mutex);
}

void double_release_001_tskentry_001 ()
{
while (1)
{
if (rand ())
{
double_release_001_tsk_001 (NULL);
}
}
}

但是当我构建它时,我得到一个错误提示

Description Resource    Path    Location    Type
undefined reference to `_imp__pthread_create'
undefined reference to `_imp__pthread_create'
undefined reference to `_imp__pthread_create'
undefined reference to `_imp__pthread_create'

我包含了 pthread.h。有人可以帮我解决这个问题吗。

最佳答案

将此选项添加到链接器:-lpthread

关于c - 未检测到多线程库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12962666/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com