强制加载库
VC中,如果隐式链接的lib或dll未被引用,编译器并不会去生成加载该lib或dll的代码,从VLD1.0版本中看到可以通过如下方式强制引用:
// Force a symbolic reference to the global VisualLeakDetector class object from
// the library. This enusres that the object is linked with the program, even
// though nobody directly references it outside of the library.
#pragma comment(linker, "/include:?visualleakdetector@@3VVisualLeakDetector@@A")
其中,“?visualleakdetector@@3VVisualLeakDetector@@A”即vldmtdll.lib中VisualLeakDetector类的构造函数,
通过dumpbin /SYMBOLS vldmtdll.lib 可以看到