为什么RWDBManager :: database需要共享库名?

时间:2011-02-07 10:01:17

标签: c++ plugins linker compilation rogue-wave

我正在使用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". 

我不明白:

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

这是一种标准技术吗?通常在哪里使用? 我曾经在使用共享库的项目上工作,所以链接不是静态的,但我没有遇到过这样的事情。

谢谢,

1 个答案:

答案 0 :(得分:1)

可能是因为他们使用它的名称和POSIX系统上的dlopen()等标准调用动态加载库。在Windows中有一个等价物,我认为它是LoadLibrary()。使用这样的系统,您可以加载库并从中获取符号。构建插件系统或类似的东西非常方便。它还允许您仅在存在时使用某些性能增强库...

请参阅here例如......

MY2C

编辑:

为什么他们选择这个设计,除了问他们之外,你必须猜测:)

我的猜测:在插件架构中更容易维护数据库驱动程序:更容易安装,在版本之间切换,更容易提供二进制补丁......

另一种猜测:实现某种内省/反思的唯一方法。