From owner-freebsd-stable Thu Dec 19 17:42:47 2002 Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6240E37B401 for ; Thu, 19 Dec 2002 17:42:42 -0800 (PST) Received: from sherryl.salk.edu (sherryl.snl.salk.edu [198.202.70.151]) by mx1.FreeBSD.org (Postfix) with ESMTP id C384543EE8 for ; Thu, 19 Dec 2002 17:42:38 -0800 (PST) (envelope-from jorge@salk.edu) Received: from merckx.snl.salk.edu (merckx.snl.salk.edu [198.202.70.90]) by sherryl.salk.edu (8.12.1/8.12.1) with ESMTP id gBK1gVu2029694; Thu, 19 Dec 2002 17:42:31 -0800 (PST) Date: Thu, 19 Dec 2002 17:42:30 -0800 (PST) From: Jorge Aldana X-X-Sender: jorge@merckx.snl.salk.edu To: Emiel Kollof Cc: freebsd-stable@FreeBSD.ORG Subject: Re: pthread woes In-Reply-To: <20021220013445.GA75547@hackerheaven.org> Message-ID: <20021219174200.T71553-100000@merckx.snl.salk.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 > #include > #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