I am using gcc 4.6.3, and I am trying to write a program that uses asynchronous flow via threads. After some research, I decided that threads.h
was best for windows and pthread.h
was best for POSIX systems. So I used pthread.h
.
After a lot of debugging, I have my code.
#include <pthread.h>
#include <stdio.h>
void *exe(){
char i;
for(i = 0; i < 0; i++){
printf("%c\n", i);
}
}
int main(){
long unsigned int *id = (void *)1ul;
int d = pthread_create(id, NULL, exe, NULL);
}
This code is not intended to be of any use, it is for me to teach myself threading.
The problem is that it throws the error
exit status 1
/file/path.o: In function `main':
main.c:(.text+0x5d): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
It seems that the pthread_create
function is undefined, but I have included the library and it didn't give me any directory not found errors.
Does anyone know why this is happening?