这是一个简单的代码,我编写它来学习在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/

10-11 19:05