强制加载库

本文详细介绍了在VC环境下如何通过代码强制引用未直接引用的lib或dll,确保其在程序中被正确链接。通过使用特定的预处理器指令,可以确保即使在lib或dll内部未被直接调用的情况下,该lib或dll也会被正确包含到程序中。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 可以看到

转载于:https://www.cnblogs.com/through/p/4946328.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值