1

我正在使用 Roguewave 库从 C++ 连接到 Sybase 数据库。我了解数据库对象的构造为:

  RWDBManager::database("accessLib", "", "", "", "", "XA=lrm_name");

http://www2.roguewave.com/support/docs/sourcepro/edition8/html/dbxaug/5-3.html

All arguments are of type RWCString. Note that establishing an XA connection to the Sybase CT database requires only two of the six database() arguments, as described here:

  accessLib

  The argument for the first parameter is the same as that which you provide for the non-XA connection.

  For static libraries, supply the string "SYBASE_CT".

  For shared libraries, supply the name of your shared access library, for example "libctl420d.so". 

我不明白:

在代码中,我习惯于看到当我们必须使用库中提供的东西时,包括该库的标头,使用该库中的类/函数,然后在编译项目时在 LDLIBARIES 列表中使用该库。为什么这里的函数库需要库的NAME?与#include 方法相比,这种方法有什么优势。

这是一些标准技术吗?这个一般用在什么地方?我从事过使用共享库的项目,因此链接不是静态完成的,但我还没有遇到过这样的事情。

谢谢,

4

1 回答 1

1

It is probably because they dynamically load the library using it's name and a standard call like dlopen() on POSIX systems. There is an equivalent in windows, I think it is LoadLibrary(). With such a system you are able to load a library and get symbols from it. Very convenient to build plugin systems or things like that. It also allows you to use some performance enhancing libraries only if they are present ...

See here for example ...

my2c

EDIT:

As why they choose this design, besides asking them, you have to guess :)

My guess : easier to maintain DB drivers in a plugin architecture : easier to install, switch between versions, easier to deliver binary patch ...

Another guess : the only way to implement some sort of introspection / reflection.

于 2011-02-07T12:42:18.630 回答