为什么 RWDBManager::database 需要共享库名称?
我正在使用 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 方法相比,此方法有哪些优点?
这是某种标准技术吗?这个一般用在什么地方呢? 我曾经从事过使用共享库的项目,因此链接不是静态完成的,但我还没有遇到过这样的事情。
谢谢,
I am using Roguewave library to connect to Sybase database from C++. I understand that database object is constructed as:
RWDBManager::database("accessLib", "", "", "", "", "XA=lrm_name");
http://www2.roguewave.com/support/docs/sourcepro/edition8/html/dbxaug/5-3.html says
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".
I don't understand:
In the code, I am used to seeing that when we have to use something provided in a library, include headers of that libraries, use classes/functions from this libraries and then while compiling your project use this library in LDLIBRARIES list. Why does the function database here needs the NAME of library? What are the advantages of this approach as against to #include approach.
Is it some standard technique? Usually where is this used?
I have worked on projects which used shared libraries and so linking was not done statically, but I haven't encountered such thing.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是因为他们使用库的名称和 POSIX 系统上的 dlopen() 等标准调用来动态加载库。 windows中有一个等价的,我认为它是
LoadLibrary()
。使用这样的系统,您可以加载库并从中获取符号。构建插件系统或类似的东西非常方便。它还允许您仅在存在某些性能增强库时使用它们...请参阅此处例如...
my2c
编辑:
至于他们选择这种设计的原因,除了询问他们之外,你还必须猜测:)
我的猜测:在插件架构中更容易维护数据库驱动程序:更容易安装,在版本之间切换,更容易交付二进制文件补丁...
另一个猜测:实现某种内省/反射的唯一方法。
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 isLoadLibrary()
. 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.