From owner-freebsd-questions@FreeBSD.ORG Thu Feb 5 01:08:08 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C433716A4CE for ; Thu, 5 Feb 2004 01:08:08 -0800 (PST) Received: from mailr-1.tiscali.it (mailr-1.tiscali.it [212.123.84.81]) by mx1.FreeBSD.org (Postfix) with ESMTP id B033F43D39 for ; Thu, 5 Feb 2004 01:08:03 -0800 (PST) (envelope-from casadeif@yahoo.it) Received: from ppp-82-84-236-236.cust-adsl.tiscali.it (HELO yahoo.it) (82.84.236.236) by mailr-1.tiscali.it with ESMTP; 05 Feb 2004 10:08:03 +0100 X-BrightmailFiltered: true Message-ID: <402207F1.9030100@yahoo.it> Date: Thu, 05 Feb 2004 10:08:01 +0100 From: Francesco Casadei User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.6b) Gecko/20040120 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Joe Lewis References: <52640.207.173.181.72.1075949311.squirrel@email.relia.net> In-Reply-To: <52640.207.173.181.72.1075949311.squirrel@email.relia.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit cc: freebsd-questions@freebsd.org Subject: Re: dlopen() and parent symbols X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 Feb 2004 09:08:08 -0000 Joe Lewis wrote: > I've read that I can't export symbols from the parent executable to > modules opened with dlopen(). So, I have a (hopefully) quick question. > How can I export function(s) to those modules? > > > Joe Lewis > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > Read the autobook at http://sources.redhat.com/autobook/ . From section 18.1: [...] For instance, your main application may provide some utility function, `my_function', which you want a module to have access to. There are two ways to do that: * You could use Libtool to link your application, using the `-export-dynamic' option to ensure that the global application symbols are available to modules. When libltdl loads a module into an application compiled like this, it will back-link symbols from the application to resolve any otherwise undefined symbols in a module. When the module is `ltdlopen'ed, libltdl will arrange for calls to `my_function' in the module, to execute the `my_function' implementation in the application. If you have need of this functionality, relying on back-linking is the simplest way to achieve it. Unfortunately, this simplicity is at the expense of portability: some platforms have no support for back-linking at all, and others will not allow a module to be created with unresolved symbols. Never-the-less, libltdl allows you to do this if you want to. * You could split the code that implements the symbols you need to share with modules into a separate library. This library would then be used to resolve the symbols you wish to share, by linking it into modules and application alike. The definition of `my_function' would be compiled separately into a library, `libmy_function.la'. References to `my_function' from the application would be resolved by linking it with `libmy_function.la', and the library would be installed so that modules which need to call `my_function' would be able to resolve the symbol by linking with `-lmy_function'. This method requires support for neither back-linking nor unresolved link time symbols from the host platform. The disadvantage is that when you realise you need this functionality, it may be quite complicated to extract the shared functionality from the application to be compiled in a stand alone library. [...] Francesco Casadei