对 pthread_create 的未定义引用 [英] Undefined reference to pthread_create

查看:70
本文介绍了对 pthread_create 的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

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

void* cuoco(void* arg)
{
    fprintf(stderr,"Inizio codice cuoco\n");
    fprintf(stderr,"Fine codice cuoco\n");
    return NULL;
}

void* cameriere(void* arg)
{
    fprintf(stderr,"Inizio codice cameriere\n");
    fprintf(stderr,"Fine codice cameriere\n");
    return NULL;
}

void* cliente(void* arg)
{
    fprintf(stderr,"Inizio codice cliente\n");
    fprintf(stderr,"Fine codice cliente\n");
    return NULL;
}

int main(int argc, char* argv[])
{
    void* (*routine)(void*);
    routine=cuoco;
    pthread_t thread_cuoco,thread_cameriere,thread_cliente;
    pthread_create(&thread_cuoco,NULL,routine,NULL);
    return 0;
}

在编译器选项中我插入 -lpthread
但它说:
对 pthread_create 的未定义引用"
我使用的是 ubuntu 10.10,所以我已经安装了 pthread 库,我想不出这个错误的原因.

And in the compiler options I insert -lpthread
But it says:
"Undefined reference to pthread_create"
I use ubuntu 10.10, so I already have pthread library installed, I can't figure the reason of this error.

推荐答案

使用 -lpthread 作为最后一个编译器标志.

Use -lpthread as the last compiler flag.

示例:gcc -o sample.c -lpthread

这篇关于对 pthread_create 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆