Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 \n");
printf ( "thread output1 \n");

 void *fun(void* data){
printf("thread output2 \n")

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

share|improve this question

closed as off topic by dobey, Radu Rădeanu, bcbc, Mitch, Uri Herrera May 31 '13 at 19:45

Questions on Ask Ubuntu are expected to relate to Ubuntu within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

this isn't related to ubuntu. i've flagged your question; it'll probably get moved to Stack Overflow. – strugee May 31 '13 at 17:51
You need to compile it as gcc -pthread -o thread thread.c. Check your makefile. – Salem May 31 '13 at 17:54
up vote 2 down vote accepted

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
share|improve this answer
thanks benjamin for help , it work but to be honest I don't understand what 'a dynamic library' mean I'll google it – Engine May 31 '13 at 18:01

According to the manual page for pthread_create and some sample code around the internet, the first parameter is a pointer to pthread_t, not pthread. Try that:

pthread_t tid;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.