Date: Thu, 19 Dec 2002 17:42:30 -0800 (PST) From: Jorge Aldana <jorge@salk.edu> To: Emiel Kollof <coolvibe@hackerheaven.org> Cc: freebsd-stable@FreeBSD.ORG Subject: Re: pthread woes Message-ID: <20021219174200.T71553-100000@merckx.snl.salk.edu> In-Reply-To: <20021220013445.GA75547@hackerheaven.org>
next in thread | previous in thread | raw e-mail | index | archive | help
I compiled it as follows and get the output listed below:
>g++ -pthread newTest.c
>./a.out
Creating thread 0
Creating thread 1
Creating thread 2
Creating thread 3
Creating thread 4
0: Hello World!
1: Hello World!
2: Hello World!
3: Hello World!
4: Hello World!
Jorge
On Fri, 20 Dec 2002, Emiel Kollof wrote:
> Hi folks,
>
> I have a problem with compiling stuff that uses POSIX threads. I used
> the following snippet of code to test:
>
> --- test.c ---
>
> #include <pthread.h>
> #include <stdio.h>
> #define NUM_THREADS 5
>
> void *PrintHello(void *threadid)
> {
> printf("\n%d: Hello World!\n", threadid);
> pthread_exit(NULL);
> }
>
> int main()
> {
> pthread_t threads[NUM_THREADS];
> int rc, t;
> for(t=0;t < NUM_THREADS;t++){
> printf("Creating thread %d\n", t);
> rc = pthread_create(&threads[t], NULL,
> PrintHello, (void *)t);
> if (rc){
> printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1);
> }
> }
> pthread_exit(NULL);
> }
>
> --- end test.c ---
>
> When I compile it, I get the following errors:
>
> % gcc test.c -o test.c
> /tmp/ccF3QI1k.o: In function `PrintHello':
> /tmp/ccF3QI1k.o(.text+0x20): undefined reference to `pthread_exit'
> /tmp/ccF3QI1k.o: In function `main':
> /tmp/ccF3QI1k.o(.text+0x76): undefined reference to `pthread_create'
> /tmp/ccF3QI1k.o(.text+0xba): undefined reference to `pthread_exit'
>
> It compiles fine when I use -lc_r. This also breaks a lot of ports. What's
> going on?
>
> Cheers,
> Emiel
> --
> The man who sets out to carry a cat by its tail learns something that
> will always be useful and which never will grow dim or doubtful.
> -- Mark Twain.
>
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-stable" in the body of the message
>
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021219174200.T71553-100000>
