Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Dec 2002 02:34:45 +0100
From:      Emiel Kollof <coolvibe@hackerheaven.org>
To:        freebsd-stable@freebsd.org
Subject:   pthread woes
Message-ID:  <20021220013445.GA75547@hackerheaven.org>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021220013445.GA75547>