Skip to Content.
Sympa Menu

freetds - Re: [freetds] DB connection library and dynamic linking

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] DB connection library and dynamic linking
  • Date: Sun, 26 Sep 2010 13:10:01 -0400

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






Archive powered by MHonArc 2.6.24.

Top of Page