From owner-freebsd-hackers@FreeBSD.ORG Sun Aug 31 12:19:29 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6E40216A4BF for ; Sun, 31 Aug 2003 12:19:29 -0700 (PDT) Received: from webserver.get-linux.org (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 7EDAC43FF7 for ; Sun, 31 Aug 2003 12:19:28 -0700 (PDT) (envelope-from oremanj@webserver.get-linux.org) Received: (qmail 6548 invoked by uid 1000); 31 Aug 2003 19:19:27 -0000 Date: Sun, 31 Aug 2003 12:19:27 -0700 From: Joshua Oreman To: Peter Wood Message-ID: <20030831191927.GA6197@webserver> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.1i cc: hackers@freebsd.org Subject: Re: Linking with -shared and -pthread... X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 Aug 2003 19:19:29 -0000 On Sun, Aug 31, 2003 at 08:13:03PM +0100 or thereabouts, Peter Wood wrote: > Good Evening, > > I've been looking at writing a program that uses both shared libraries > (dlopen/dlclose) and POSIX threads. I however haven't had any success in my > simple tests. > > After doing some research via google I found that due to -shared pthreads > wasn't linked into the shared library, fair enough, it's logical. > > My question is, is it possible to write programs that use pthreads in their > shared libraries on FreeBSD. > > For compiling the base program (that is the program that loads the shared > libraries) I've been using: > > gcc -export-dynamic -pthread master.c -o master I use something like gcc -Wl,-export-dynamic master.c -o master -lc_r > > And for each of the shared libaries I've been using: > > gcc -shared -pthread slave.c -o slave.so I use gcc -shared -fPIC -DPIC slave.c -o slave.so The pthread functions from `master' will automatically be exported to `slave'. -- Josh