如何禁用导入库的生成?
我正在 Visual Studio 中创建一个 COM DLL。链接器为 DLL 生成导入库。我不需要导入库。
有什么办法告诉链接器不要生成它吗?
I'm creating a COM DLL in Visual Studio. The linker generates an import library for the DLL. I don't need the import library.
Is there any way to tell the linker not to generate it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
九年后,这可能对 OP 没有用,但可能对其他寻求解决方案的人有用。
LINK.EXE 支持
/NOIMPLIB
选项,该选项可防止创建导入库,即使在DLL
__declspec(dllexport) 例程也是如此> 或EXE
被链接。转到“项目属性”,打开“链接器”部分。最后一个选项是
命令行
。选择它,底部有一个地方可以向链接器添加其他选项。在编辑字段中输入/NOIMPLIB
,保存并应用,它将阻止创建.lib
文件。-- 编辑 --
不幸的是,虽然它确实阻止了
.lib
文件的创建,但根据经验,我发现.exp
文件仍然被创建。我会向微软提交一份错误报告,但根据他们开发工具团队过去的经验,试图解决这样的问题就像试图将巨石滚上山一样。-- 编辑 -- 四年后 --
正如评论中所述,VS 2019 终于解决了这个问题,因此
/NOIMPLIB
现在禁止创建.lib
和.exp
文件。Nine years later, this may not be useful to the OP, but it may prove useful to others coming by looking for a solution.
LINK.EXE supports the
/NOIMPLIB
option that prevents creation of an import library, even in the presence of a__declspec(dllexport)
routine in theDLL
orEXE
being linked.Go to Project Properties, open up the
Linker
section. The very last option isCommand Line
. Select that, and there's a place at the bottom to add additional options to the linker. Enter/NOIMPLIB
in the edit field, save and apply, and it'll prevent the creation of the.lib
file.-- Edit --
Unfortunately, while it does prevent creation of the
.lib
file, empirically I've found that the.exp
file is still created. I'd file a bug report with MS, but based on past experience with their developer tools team, trying to get something like this fixed will be akin to trying to roll a boulder up hill.-- Edit -- four years later --
As noted in the comments, VS 2019 finally has this fixed, so that
/NOIMPLIB
now suppresses the creation of both the.lib
and.exp
files.这个答案似乎是解决方案:
https://stackoverflow.com/a/15214141/660440
“使用包含导出函数的 .def 文件,并用PRIVATE 关键字将告诉链接器跳过将符号放入导入库中。”
This answer seems to be the solution:
https://stackoverflow.com/a/15214141/660440
"Using a .def file containing your exported functions marked with the PRIVATE keyword will tell the linker to skip placing the symbol in your import library."