[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamically linking one of mysq, postgresql or sqlite3

From: santilistas
Subject: Re: dynamically linking one of mysq, postgresql or sqlite3
Date: Tue, 15 Sep 2009 00:14:50 +0200
User-agent: Mozilla-Thunderbird (X11/20090706)

I've done so, following the wonderful tntdb library.

After a great deal of prouding aroung, I have managed to build and load
the shared library, and create an object through a C function in the
shared library:

extern "C" {
void *new_connection()
  MySql_dbConnection *new_conn = new MySql_dbConnection();
  return new_conn;

Everything fine up to this, but when in the main program I try to use a
virtual member of this MySql_dbConnection object, I get a segmentation

The address of the pointers seem wierd to me:

My main function has address: 0x8069ac4 [int main(int, char**)]
The new_connection function in my library has address: 0xb7fb00dc [void*
The MySql_dbConnection object returned by new_connection() has address:
And the main connection object declared in the main program (that
contains a pointer to the object in the library) has address: 0xbfdd66c8

It seems to me that the value 0x92753d0 for the connection created by
the library is suspicious. Can it be the reason for my segfault?


new_connection:0xb7fb00dc [void* new_connection()]

Bob Friesenhahn wrote:
> On Fri, 11 Sep 2009, santilin wrote:
>> Hi, I'm quite new to libtool though I have read the tree GNU manuals:
>> automake, autoconf and libtool.
>> I want to solve the typical problem of loading dinamically one of the
>> sql servers drivers from my own shared library.
>> I know I have to create a common interface for the drivers.
>> What I am not sure is wheter I must use dlopen or there is any other way
>> of loading the library. If I use dlopen, lets say, to open, I
>> have to read all the symbols and use pointers to them, which is a lot of
>> work. I wonder if there is a way of loading the libraries the same way
>> they are loaded when they are linked within the main program.
> I believe that you can use libltdl from libtool 2.X to do this by
> using lt_dlopenadvise() with the lt_dladvise_global option.  This
> invokes dlopen() with the RTLD_GLOBAL flag.
> I don't recommend that you do this since it introduces ordering
> problems, is NOT PORTABLE, and does not solve the static linkage
> issue.  If your code accidentally references a symbol before it is
> defined, then your program goes "poof".
> If you design a common interface for the drivers, then you can use
> libltdl to locate just one symbol in the driver which is a
> registration function which registers all of the interface functions
> that the driver supports.  You could pass a structure containing all
> of the possible function vectors and the driver module updates it, or
> you could have the module call back into your library (which it can
> do) and add itself as a driver.  This is more efficient than using
> libltdl to search for all of the possible symbols (some of which may
> not exist).  This allows all of the implementation functions (except
> for the registration function) to be 'static' since they don't require
> external visibility.
> Bob
> -- 
> Bob Friesenhahn
> address@hidden,
> GraphicsMagick Maintainer,
> _______________________________________________

reply via email to

[Prev in Thread] Current Thread [Next in Thread]