lib.exe,Visual Studio,从 dll 和 def 文件生成 .lib 文件
我是 Windows 和 Visual Studio 的新手。我必须编译用 C++ 编写的代码。它使用不同的库。我找到了这些库的 dll 文件。我可以毫无问题地编译源代码,但存在链接问题。我不知道如何链接dll文件。我知道我需要 .lib 文件。但某些所需的库没有提供任何 lib 文件。只有dll文件和dif文件。如何使用 Visual Studio 2010 Ultimate 生成所需的 lib 文件?我找不到名为 lib.exe 的程序。谢谢。
I am new to windows and visual studio. I have to compile a code written in c++. It uses different libraries. I found the dll files for those libraries. I can compile the source without any problem but there are link problems. I do not know how to link dll files. I understood that I need .lib files for that. But some of the libraries required do not have any lib files provided. There are only dll files and dif files. How can I generate the required lib files by using Visual studio 2010 ultimate? I cannot find a program called lib.exe. Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确实需要 lib.exe 将 .def 文件转换为链接器需要的 .lib 文件。它存储在Visual Studio目录的vc\bin目录下,默认为C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\lib.exe。最简单的方法是使用“Visual Studio 命令提示符”,您可以在“开始”菜单、Microsoft Visual Studio 2010、Visual Studio 工具中找到它。
接下来,使用 /def:foo.def 选项运行 lib.exe 以生成 .lib。请遵循供应商的说明(如果提供)。请随时联系他们寻求支持。
You are indeed going to need lib.exe to turn the .def file into a .lib file that the linker needs. It is stored in the vc\bin directory of the visual studio directory, C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\lib.exe by default. The easiest way is to use the "Visual Studio Command Prompt", you'll find it in the Start menu, Microsoft Visual Studio 2010, Visual Studio Tools.
Next, run lib.exe with the /def:foo.def option to generate the .lib. Follow the vendor's instructions, if provided. And don't hesitate to contact them for support.
如果您转到 DLL 的项目属性并检查链接器 ->高级中有一个“导入库”条目。您可能必须在构建 DLL 时对其进行设置才能生成 lib 文件,或者如果它已经设置,它应该将您指向 lib 文件的位置。
也就是说,如果您使用 Visual Studio 2010 构建整个项目,则在项目的“公共属性”参考部分中添加依赖库应该会自动触发必要的链接语句。
If you go to the project properties for the DLL and check Linker -> Advanced, there is an entry for 'Import Library'. You might have to set that to generate a lib file while building the DLL or if it is already set it should point you at the location of the lib file.
That said if you build the whole project using Visual Studio 2010, adding the dependent libraries in the project's Common Properties' Reference section should automatically trigger the necessary link statements.
这确实需要大量工作,通常更容易在 google 上搜索所需 DLL 的源代码和/或库,因为使用相同的编译器编译库和程序是一个好主意(使部署更容易,因此您不依赖于多个 vc 运行时)。
您可以使用本指南创建 .lib 文件: http://support.microsoft.com/kb/131313
这是一个需要时间以及大量调试的过程(取决于 dll 的大小以及 dll 的复杂性)接口)
根据您的平台,位置通常为:
Windows 7 32 位和 32 位 VS2010:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\
Windows 7 64 位和 64 位 VS2010:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin`
Windows 7 64 位与 32 位 VS2010:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
但是,如果启动 Visual Studio 命令提示符,它应该位于您的路径中。 (在开始菜单上的 Visual Studio Tools 下查看)
This does require a lot of work, and usually it's easier to google for the source and/or libs for the DLL's you need, as it's a good idea to compile both libraries and your program with the same compiler (Makes deployment easier, so you aren't dependant on multiple vc runtimes).
You can use this guide to create the .lib files: http://support.microsoft.com/kb/131313
It is a process that takes time, as well as a lot of debugging (Depending on the size of the dll's as well as the complexity of the dll's interfaces)
Depending on your platform, the location is usually:
Windows 7 32-bit with 32-bit VS2010:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\
Windows 7 64-bit with 64-bit VS2010:
C:\Program Files\Microsoft Visual Studio 10.0\VC\bin`
Windows 7 64-bit with 32-bit VS2010:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\
However, if you start the Visual Studio Command Prompt, it should be in your path. (Look under Visual Studio Tools on your start-menu)
如果您确实需要查找 lib.exe,我有一个 Python 脚本,可以在任何以分号分隔的文件夹组中查找您想要的任何内容。
在您的情况下,请像这样使用它(在 VS Developer 命令提示符中):
如果您不想找到它,只需像这样使用它(在 VS Developer 命令提示符中):
If you REALLY need to FIND lib.exe, I have a Python script that finds whatever you want in whatever semicolon-separated folder group.
In your case, use it like this (in VS Developer Command Prompt):
If you don't want to find it, just use it like this (in VS Developer Command Prompt):