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
_______________________________________________________________
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!