简体   繁体   English

尝试从Visual Studio命令提示符处调用lib.exe

[英]Trying to call lib.exe from Visual Studio Command Prompt

I am trying to call lib.exe from the Visual Studio Command Prompt so I can build the .lib file from my .def file. 我试图从Visual Studio命令提示符中调用lib.exe,以便可以从.def文件构建.lib文件。 When I run this: 当我运行这个:

lib.exe /MACHINE:X86 /DEF:MyDLL.def lib.exe /机器:X86 /DEF:MyDLL.def

In the end I want to export my functions to be used when I call them from within a DLL. 最后,我想导出在DLL中调用函数时要使用的函数。 I am having to create this library because I have 2 DLLs and the first one calls the second one. 我必须创建此库,因为我有2个DLL,第一个调用第二个。 The second one I just have the DLL itself and do not have the header or the .cpp file. 第二个我只是拥有DLL本身,没有头文件或.cpp文件。 I do not have the .lib file hence why I am trying to create one. 我没有.lib文件,因此为什么要尝试创建一个。 I have used this tool expdef - def file generator to create my .def file and following this tutroial: How To Create 32-bit Import Libraries Without .OBJs or Source , so I could build the library file. 我已经使用此工具expdef-def文件生成器来创建.def文件,并遵循以下教程: 如何在没有.OBJs或Source的情况下创建32位导入库 ,因此可以构建库文件。

The error I receive from the command prompt is: 我从命令提示符处收到的错误是:

LINK : fatal error LNK1104: cannot open file 'MyDLL.def' 链接:致命错误LNK1104:无法打开文件'MyDLL.def'

So I have tried searching through many forums and searches but cannot find a solution to why I see this. 因此,我尝试在许多论坛和搜索中进行搜索,但是找不到找到此原因的解决方案。

I have posted this on another forum here where it explains what I totally want to do. 我已将此内容发布在另一个论坛上,在此解释了我完全想做的事情。

Another option if you don't have and export .lib for a DLL is to the Win32 APIS LoadLibrary() and GetProcAddress(). 如果您没有并为DLL导出.lib,则另一个选择是将Win32 APIS LoadLibrary()和GetProcAddress()导出。 Call these APIs from the caller code, using the names of the exported entry points of the callee DLL. 使用被调用者DLL的导出入口点的名称,从调用者代码中调用这些API。 You don't need to mention the callee DLL at all when linking the first DLL. 链接第一个DLL时,您根本不需要提及被调用者DLL。

To get the names of the exported entry points, you can use a tool like "dumpbin /exports" or depends.exe on the callee DLL. 若要获取导出的入口点的名称,可以在被调用方DLL上使用“ dumpbin / exports”或Depends.exe之类的工具。

Of course, you have to know the signatures and any other assumptions of the called entry points, or you will get undefined behavior. 当然,您必须知道被调用入口点的签名和任何其他假设,否则您将获得未定义的行为。 If worst comes to worst, you may be able to deduce these by debugging the call. 如果情况变得更糟,则可以通过调试调用来推断出这些情况。

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

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