简体   繁体   English

lib.exe,Visual Studio,从 dll 和 def 文件生成 .lib 文件

[英]lib.exe, Visual Studio, generating .lib files from dll's and def files

I am new to windows and visual studio.我是 Windows 和 Visual Studio 的新手。 I have to compile a code written in c++.我必须编译用 C++ 编写的代码。 It uses different libraries.它使用不同的库。 I found the dll files for those libraries.我找到了这些库的 dll 文件。 I can compile the source without any problem but there are link problems.我可以毫无问题地编译源代码,但存在链接问题。 I do not know how to link dll files.我不知道如何链接 dll 文件。 I understood that I need .lib files for that.我知道我需要 .lib 文件。 But some of the libraries required do not have any lib files provided.但是一些所需的库没有提供任何 lib 文件。 There are only dll files and dif files.只有dll文件和dif文件。 How can I generate the required lib files by using Visual studio 2010 ultimate?如何使用 Visual Studio 2010 Ultimate 生成所需的 lib 文件? I cannot find a program called lib.exe.我找不到名为 lib.exe 的程序。 Thank You.谢谢你。

You are indeed going to need lib.exe to turn the .def file into a .lib file that the linker needs.您确实需要 lib.exe 将 .def 文件转换为链接器需要的 .lib 文件。 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.存放在visual studio目录的vc\\bin目录下,默认为C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin\\lib.exe。 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.最简单的方法是使用“Visual Studio 命令提示符”,您可以在“开始”菜单、Microsoft Visual Studio 2010、Visual Studio 工具中找到它。

Next, run lib.exe with the /def:foo.def option to generate the .lib.接下来,使用 /def:foo.def 选项运行 lib.exe 以生成 .lib。 Follow the vendor's instructions, if provided.如果提供,请遵循供应商的说明。 And don't hesitate to contact them for support.不要犹豫,联系他们寻求支持。

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).这确实需要大量的工作,通常更容易为您需要的 DLL 搜索源代码和/或库,因为使用相同的编译器编译库和程序是个好主意(使部署更容易,所以你不依赖于多个 vc 运行时)。

You can use this guide to create the .lib files: http://support.microsoft.com/kb/131313您可以使用本指南创建 .lib 文件: 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)这是一个需要时间和大量调试的过程(取决于dll的大小以及dll接口的复杂性)

Depending on your platform, the location is usually:根据您的平台,位置通常是:

  • Windows 7 32-bit with 32-bit VS2010: Windows 7 32 位与 32 位 VS2010:

    C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin\\ C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin\\

  • Windows 7 64-bit with 64-bit VS2010: Windows 7 64 位与 64 位 VS2010:

    C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin` C:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\bin`

  • Windows 7 64-bit with 32-bit VS2010: Windows 7 64 位与 32 位 VS2010:

    C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\bin\\ 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.但是,如果您启动 Visual Studio 命令提示符,它应该在您的路径中。 (Look under Visual Studio Tools on your start-menu) (在开始菜单上的 Visual Studio 工具下查看)

If you go to the project properties for the DLL and check Linker -> Advanced, there is an entry for 'Import Library'.如果您转到 DLL 的项目属性并检查链接器 -> 高级,则会有一个“导入库”条目。 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.您可能需要设置它以在构建 DLL 时生成一个 lib 文件,或者如果它已经设置,它应该将您指向 lib 文件的位置。

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.也就是说,如果您使用 Visual Studio 2010 构建整个项目,在项目的公共属性的参考部分中添加依赖库应该会自动触发必要的链接语句。

If you REALLY need to FIND lib.exe, I have a Python script that finds whatever you want in whatever semicolon-separated folder group.如果您真的需要查找 lib.exe,我有一个 Python 脚本,可以在任何以分号分隔的文件夹组中查找您想要的任何内容。

import sys
import os
def select(a, b):
    d = []
    for c in a:
        d.append(b(c))
    return d
def multicheck(filename, folders_SEMICOLONSEPARATED):
    folders = folders_SEMICOLONSEPARATED.split(";")
    print("RESULTS:")
    k = True
    for f in folders:
        try:
            if filename.lower() in select(os.listdir(f), lambda k: k.lower()):
                k = False
                print("  " + os.path.join(f, filename))
        except:
            pass
    if k:
        print("  NONE")
if __name__ == "__main__":
    multicheck(sys.argv[1], sys.argv[2])

In your case, use it like this (in VS Developer Command Prompt):在您的情况下,像这样使用它(在 VS 开发人员命令提示符中):

WHATEVER_YOU_CALL_IT.py lib.exe "%PATH%"

If you don't want to find it, just use it like this (in VS Developer Command Prompt):如果您不想找到它,只需像这样使用它(在 VS Developer Command Prompt 中):

LIB [options] [files]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM