为什么我不能使用pthread_creat? [英] Why I can't use pthread_creat ?

查看:84
本文介绍了为什么我不能使用pthread_creat?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

void* thread_main(void *argument){

        int i;
        int cnt = *((int*)argument);

        for(i = 0; i < cnt; i++){
                sleep(1);
                puts("working....");
        }
        return NULL;
}


int main(){

        pthread_t t_id;
        int thread_param = 5;

        if(pthread_creat(&t_id, NULL, thread_main, (void*)&thread_param) != 0){
                puts("pthread_creat() error ");
                return -1;
        };

        sleep(10);
        puts("main end");
        return 0;
}










>> gcc -o thread thread.c -lpthread
thread.c: In function ‘main’:
thread.c:23:5: warning: implicit declaration of function ‘pthread_creat’ [-Wimplicit-function-declaration]
  if(pthread_creat(&t_id, NULL, thread_main, (void*)&thread_param) != 0){
     ^
/tmp/ccERlxNy.o: In function `main':
thread.c:(.text+0x81): undefined reference to `pthread_creat'
collect2: error: ld returned 1 exit status







这是对基本工作线程的测试。但我无法编译这个。有什么问题?



OS是linux ubuntu 64bit



我尝试了什么: < br $>


i尝试链接使用gcc -l选项,但它无效。



thread.c: (.text + 0x81):谷歌搜索中对'pthread_creat'的未定义引用,每个答案都相同,只需添加-lpthread。有什么问题



头文件












It's test for basic working thread. but I can't compile this. what's the problem?

OS is linux ubuntu 64bit

What I have tried:

i try to link use gcc -l option, but it was not working.

thread.c:(.text+0x81): undefined reference to `pthread_creat' in google search, every answer are same, just add -lpthread . what the problem

header files




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

推荐答案

正确拼写 pthread_create ,如图所示在 pthread_create(3) - Linux手册页 [ ^ ]。
Try spelling pthread_create correctly, as shown at pthread_create(3) - Linux manual page[^].


pthread_create

你到底错过了什么。

最好使用像eclipse这样的IDE作为开发工作,你可以简单地避免这些错误并节省时间。 />
Eclipse是免费的。

你也可以使用代码块或代码灯。
pthread_create
You missed e in the end.
Better to use some IDE like eclipse for your dev work, where you can simply avoid these kind of mistakes and save time.
Eclipse is free.
You can also use code block or code light.


这篇关于为什么我不能使用pthread_creat?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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