[ILUG] threads compilation problem

Mark Fallon mfallon at ie.oracle.com
Tue Mar 14 12:24:57 GMT 2000


john carter wrote:
> 
> hi
> when i compile the file below using gcc abthread.c I get the following type of errors .
> 
> /tmp/cc4WfL0U.o(.text+0x6b) undefined reference to pthread_create
> /tmp/cc4WfL0U.o(.text+0xd7) undefined reference to pthread_join
> 
> any ideas
> thanks john
> 
> heres the file
> 
> /* Creates two threads, one printing 10000 "a"s, the other printing
>    10000 "b"s.
>    Illustrates: thread creation, thread joining. */
> 
> #include <stddef.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <pthread.h>
> 
> void * process(void * arg)
> {
>   int i;
>   fprintf(stderr, "Starting process %s\n", (char *) arg);
>   for (i = 0; i < 10000; i++) {
>     write(1, (char *) arg, 1);
>   }
>   return NULL;
> }
> 
> int main(void)
> {
>   int retcode;
>   pthread_t th_a, th_b;
>   void * retval;
> 
>   retcode = pthread_create(&th_a, NULL, process, (void *) "a");
>   if (retcode != 0) fprintf(stderr, "create a failed %d\n", retcode);
>   retcode = pthread_create(&th_b, NULL, process, (void *) "b");
>   if (retcode != 0) fprintf(stderr, "create b failed %d\n", retcode);
>   retcode = pthread_join(th_a, &retval);
>   if (retcode != 0) fprintf(stderr, "join a failed %d\n", retcode);
>   retcode = pthread_join(th_b, &retval);
>   if (retcode != 0) fprintf(stderr, "join b failed %d\n", retcode);
>   return 0;
> }
> 
>  for jokes check out www.csn.ul.ie/~mtbclub/john/jokes
> _____________________________________
> 
> Get your free E-mail at http://www.ireland.com
> 
> --
> Irish Linux Users' Group: ilug at linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at linux.ie

try add -lpthread to your compile line.
The reason you are getting undefined symbols is because
the linker can not find the thread functions in the list
of default libraries it includes.



Mark
-- 
_______________________________________________________________

Mark Fallon			E-mail : mfallon at ie.oracle.com
Senior Software Engineer	Phone  : +353-1-8033207
Product Line Engineering	Fax    : +353-1-8033221
_______________________________________________________________




More information about the ILUG mailing list