我正在使用 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".
我不明白:
在代码中,我习惯于看到当我们必须使用库中提供的东西时,包括该库的 header ,使用该库中的类/函数,然后在编译您的项目时使用 LDLIBRARIES 列表中的该库。为什么这里的函数数据库需要库的NAME?与#include 方法相比,这种方法的优点是什么。
这是一些标准技术吗?一般用在什么地方? 我从事过使用共享库的项目,因此链接不是静态完成的,但我还没有遇到过这样的事情。
谢谢,
最佳答案
这可能是因为他们在 POSIX 系统上使用它的名称和标准调用(如 dlopen()
)动态加载库。在windows中有一个等效的,我认为它是LoadLibrary()
。使用这样的系统,您可以加载库并从中获取符号。构建插件系统或类似的东西非常方便。它还允许您仅在存在某些性能增强库时使用它们……
参见 here例如……
我的2c
编辑:
至于他们为什么选择这个设计,除了问他们,你还得猜:)
我的猜测:在插件架构中更容易维护数据库驱动程序:更容易安装,版本之间切换,更容易交付二进制补丁......
另一个猜测:实现某种内省(introspection)/反射(reflection)的唯一方法。
关于c++ - 为什么 RWDBManager::database 需要共享库名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4919953/