Friday, April 19, 2024
Homepage · c
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3722  / 3 Years ago, sun, september 26, 2021, 9:16:35

I have a small a program that should start a 2nd Thread. the problem is that, when try to make an executable file of this program using make. I get :



 engine@ubuntu:~/Desktop/Lecture$ make thread
cc thread.c -o thread
thread.c: In function ‘main’:
thread.c:10:2: error: unknown type name ‘pthread’ .............


here is my code :



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

void *func(void*);

int main(){

pthread tid;
if (pthread_create(&tid,NULL,fun,NULL)!= 0 ){
printf("error by _ pthread
");
}
printf ( "thread output1
");
sleep(1);
return EXIT_SUCCESS;
}

void *fun(void* data){
printf("thread output2
")
}


I don't think that program is wrong, it maybe the way I'm running the make command ?



any Idea why do I get this.
thanks in advance for your help


More From » c

 Answers
0

Did you forget to link a dynamic library?




cc thread.c -o thread -lpthread




Further errors:





  • type of pthread is pthread_t

  • you misspelled fun and func

  • no semicolon in function after printf



[#30939] Monday, September 27, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ardingiba

Total Points: 497
Total Questions: 95
Total Answers: 109

Location: Gabon
Member since Sat, Jan 15, 2022
2 Years ago
;