I am using Dev C++ version 126.96.36.199 in windows environment, I have added "Open Source POSIX Threads for Win32" but when i am try to run program it shows Linking Error
[Linker error] undefined reference to `_imp__pthread_exit'
[Linker error] undefined reference to `_imp__pthread_create'
[Linker error] undefined reference to `_imp__pthread_join'
Please let me know how I resolve this issue ASAP .
/* Includes */
#include <unistd.h> /* Symbolic Constants */
#include <sys/types.h> /* Primitive System Data Types */
#include <errno.h> /* Errors */
#include <stdio.h> /* Input/Output */
#include <stdlib.h> /* General Utilities */
#include <pthread.h> /* POSIX Threads */
#include <string.h> /* String handling */
/* prototype for thread routine */
void *print_message_function ( void *ptr );
/* struct to hold data to be passed to a thread
this shows how multiple data items can be passed to a thread */
typedef struct str_thdata
* print_message_function is used as the start routine for the threads used
* it accepts a void pointer
void *print_message_function ( void *ptr )
data = (thdata *) ptr; /* type cast to a pointer to thdata */
/* do the work */
printf("Thread %d says %s \n", data->thread_no, data->message);
pthread_exit(0); /* exit */
} /* print_message_function ( void *ptr ) */
pthread_t thread1, thread2; /* thread variables */
thdata data1, data2; /* structs to be passed to threads */
/* initialize data to pass to thread 1 */
data1.thread_no = 1;
/* initialize data to pass to thread 2 */
data2.thread_no = 2;
/* create threads 1 and 2 */
pthread_create (&thread1, NULL, print_message_function, (void *) &data1);
pthread_create (&thread2, NULL, print_message_function, (void *) &data2);
/* Main block now waits for both threads to terminate, before it exits
If main block exits, both threads exit, even if the threads have not
finished their work */
/* exit */
} /* main() */
Log in to post a comment.