gcc -lpthread a.c causes problem; gcc a.c -lpthread doesn't
$ cat a.c
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#define NUM_THREADS 5
void *PrintHello(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_
}
int main (int argc, char *argv[])
{
pthread_t threads[
int rc;
long t;
for(t=0; t<NUM_THREADS; t++){
printf("In main: creating thread %ld\n", t);
rc = pthread_
if (rc){
exit(-1);
}
}
/* Last thing that main() should do */
pthread_
}
$
$ gcc a.c -lpthread
$
$ gcc -lpthread a.c
/tmp/cc30vqGC.o: In function `main':
a.c:(.text+0x81): undefined reference to `pthread_create'
collect2: ld returned 1 exit status
$
$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- mycae
- Solved:
- Last query:
- Last reply: