0

I'm making a program which change the focus of many windows by using a thread.

pthread_t getFocus;
pthread_create ( &getFocus, NULL, returnFocus, NULL );
pthread_join ( getFocus, NULL );

void *returnFocus ( void *argument ) {
    return 0;
}

When compiling, I get this error:

undefined reference to _imp__pthread_create 
undefined reference to _imp__pthread_join

What should I do to correct this error?

Stefano Sanfilippo
  • 32,265
  • 7
  • 79
  • 80

1 Answers1

0

When using using pthread you also need to link with the pthread librairy using -lpthread option.

gcc -o myprog myprog.c -lpthread

EDIT:

As Maxim said in the commentaries, the portable way to do so is:

gcc -o myprog myprog.c -pthread

-lpthread is the Unix way to do it (the one I learnt), but you should always use -pthread, and if not available (or if you have a very specific reason), use -lpthread.

On linux -lpthread mean "link with the pthread librairy", while -pthread just say "do w/e you need to do for pthread", from what I read.

  • Non-portable option. Use `-pthread` for both compiler and linker. – Maxim Egorushkin Jun 17 '14 at 11:31
  • @Maxim Ok, didnt knew. I'm from linux environement and I always used -lpthread. (edit) And I also havn't read the commentaries. Should I delete this answer? –  Jun 17 '14 at 11:32