本文介绍了如何检测多个lib版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我创作了几个原生DLL(称之为A,B和C)。这些

库之间有相互引用(A调用B调用C)。

这些库是在调试中生成的,并且可供调用者使用。和

" release"版本。这些库的发行版本是A,B和C

(.lib和.dll),而调试版本是A_debug,B_debug和C_debug

(。 lib和.dll)。


现在,因为这些库保持内部状态并调用每个其他的b / b $ b $如果调用者与发布链接版本一个

库和另一个库的调试版本。在运行时,这会导致

同时加载某些库的两个版本。 (对于

示例,如果用户调用A的调试版本,调用B的调试版本,然后用户显式调用该版本

版本的B,然后B和B_debug将同时加载,每个都有自己的内部状态
。)


所以,如何检测程序何时引用我的库和另一个库的发行版本之一的调试版本?理想情况下,我希望

将一些魔法放入导致链接器错误的源代码中。

或者,我想我可能有某种方式的DLL初始化代码

检测何时加载了多个DLL实例。


TIA - Bob

解决方案



另一种方法是自己专门拉入所需的库:


#ifdef _DEBUG

#pragma comment(lib," xerces-lb_2D.lib")

#pragma comment(lib," xalan-lb_1D.lib")

#else

#pragma comment(lib," xerces-lb_2.lib")

#pragma comment(lib," xalan-lb_1.lib" )

#endif // _DEBUG


(显然,这段代码正在使用xerces和xalan库)

全部你需要做的是确保路径设置为找到.libs。


我已经使用了同样的东西的其他3rdParty库 -

通常在头文件中。 (比如RogueWave的黄貂鱼)


Dave Connet





另一种方法是自己专门拉入所需的库:


#ifdef _DEBUG

#pragma comment(lib," xerces-lb_2D.lib")

#pragma comment(lib," xalan-lb_1D.lib")

#else

#pragma comment(lib," xerces-lb_2.lib")

#pragma comment(lib," xalan-lb_1.lib")

#endif // _DEBUG



谢谢戴夫。不幸的是,这对我的情况并没有帮助。 (请看看我的第二个帖子看看
。希望它比我的原始帖子更清晰。)如果调用者显式链接到
一个库和另一个库的发布版本然后事情就不用了b $ b工作正常。添加更多的库引用(尽管是正确的)

编程上没有帮助,因为链接器可能仍然会结束与不正确的库链接的


Hi all,

I have authored several native DLLs (call them A, B, and C). These
libraries have references between each other (A calls B which calls C).
These libraries are built and made available to callers both in "debug" and
"release" versions. The release versions of the libraries are A, B, and C
(.lib and .dll), while the debug versions are A_debug, B_debug, and C_debug
(.lib and .dll).

Now, because these libraries maintain internal state and call into each
other, ugly things happen if a caller links with the release version of one
library and the debug version of another library. At run-time, this causes
both versions of some of the libraries to be simultaneously loaded. (For
example, if the user calls into the debug version of A, which calls into the
debug version of B, and then the user explicitly calls into the release
version of B, then both B and B_debug would be simultaneously loaded, each
with its own internal state.)

So, how can I detect when a program references the debug version of one of
my libraries and the release version of another library? Ideally, I''d like
to put some magic into the source code that causes a linker error.
Alternatively, I guess I could have DLL initialization code that somehow
detects when more than one instance of the DLL have been loaded.

TIA - Bob

解决方案

Another way is to specifically pull in the required library yourself:

#ifdef _DEBUG
#pragma comment(lib, "xerces-lb_2D.lib")
#pragma comment(lib, "xalan-lb_1D.lib")
#else
#pragma comment(lib, "xerces-lb_2.lib")
#pragma comment(lib, "xalan-lb_1.lib")
#endif // _DEBUG

(Obviously, this code was making use of the xerces and xalan libraries)
All you need to do is make sure the path is set to find the .libs.

I''ve made use of other 3rdParty libraries that do the same thing -
usually in a header file. (Like RogueWave''s Stingray)

Dave Connet




Another way is to specifically pull in the required library yourself:

#ifdef _DEBUG
#pragma comment(lib, "xerces-lb_2D.lib")
#pragma comment(lib, "xalan-lb_1D.lib")
#else
#pragma comment(lib, "xerces-lb_2.lib")
#pragma comment(lib, "xalan-lb_1.lib")
#endif // _DEBUG

Thanks Dave. Unfortunately, that doesn''t really help my situation. (Take a
look at my second posting. Hopefully it''s a little bit clearer than my
original posting.) If a caller explicitly links with the debug version of
one library and the release version of another library then things don''t
work correctly. Adding more library references (albeit correct ones)
programmatically doesn''t help things, since the linker may still wind up
linking with the incorrect library.


这篇关于如何检测多个lib版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 02:55