Re: DB connection library and dynamic linking

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
Julian Amso wrote:
> 
> Since both the FreeTDS library and Sybase Open Client library has a
> ct-lib implementation. I am facing problem of forcing the application to
> use the "right" library for connection. What I need is following
> scenario
> 
> FreeTDS (I have the soruce code) -> MSSQL DB connection
> Sybase Open Client (external library) -> Sybase DB connection
> 
> Is there any way to force to code, compile or link application to choose
> a specific library in the code.

It's an ugly problem, isn't it?  I have a solution for you which is a
little tedious but not difficult, just a few hours work.  If you do the
work and send a patch, I'll apply it to the mainline code. 

Compilers and linkers rely on names to communicate which function is
invoked.  From the linker's point of view, there isn't "a sybase library"
and "a FreeTDS library".  There are only names: ct_connect(), etc.  It
selects the first function whose name matches the one requested by the
object file from the libraries it is told to choose from.  

You have two libraries that use the same name for (obviously) different
functions, what's known as a namespace conflict.  The only solution is to
use different names.  

A systematic solution would be to prefix all the FreeTDS ct-lib names
throughout the library, and use the preprocessor in ct.c to DTRT.  We do
that for db-lib's dbopen():

	sybdb.h:720 DBPROCESS *tdsdbopen(LOGINREC * login, 
				const char *server, int msdblib);
	sybdb.h:724 #define dbopen(x,y) tdsdbopen((x),(y), 1)
	dblib.c:1122 tdsdbopen(LOGINREC * login, 
				const char *server, int msdblib)

because other libraries define their own dbopen().  

It's not really that big a job, either:

$ grep ct_ doc/api_status.txt | awk '/OK/ {print $3}' | wc -l
      31

31 functions to rename in src/ct-lib, and 31 preprocessor macros.  Then
it's fixed, once and for all. 

HTH.  

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.