设置 win32 控制台应用程序的库路径
当我尝试执行简单的“HelloWorld”win32 控制台应用程序时,出现“找不到 dll:重新启动应用程序可能会解决问题”错误。 我知道 .dll 的位置。 从命令提示符执行 .exe 时如何指定其位置?
PS:将.dll复制到.exe的当前目录似乎可以解决问题,但这种方法不适合这种情况。
I am getting "dll not found:restarting the application may fix the problem" error when i try to execute a simple "HelloWorld" win32 console application.
I know the location of the .dll.
How to specify its location when executing the .exe from command prompt?
PS: copying the .dll to the .exe's current dir seems to solve the problem, but this approach is not suitable in this case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
DLL 加载发生在 Windows 管道的深处。
如果在与应用程序相同的目录中找不到 DLL,则会自动扫描 PATH 以查找该目录。
因此,解决问题的最简单方法是将包含 DLL 的目录添加到您的 PATH 中。 根据代码需要加载 DLL 的时间,您可以(暂时)从“HelloWorld”应用程序内部修改 PATH。
DLL loading happens deep in the plumbing of windows.
If the DLL is not found in the same directory as the application, the PATH is automatically scanned in order to find the directory.
So, the simplest answer to your problem is to add the directory containing the DLL to your PATH. Depending on when the DLL needs to be loaded by your code, you may be able to (temporarily) modify the PATH from inside your "HelloWorld" application.
LoadLibraryEx 的文档有一些关于如何进行的讨论Windows 搜索您的 dll。 如果您可以构造 DLL 的完整路径或使用 SetDllDirectory 函数将目录添加到搜索路径。
The documentation for LoadLibraryEx has some discussion on how Windows searches for your dll. You might try using the LOAD_WITH_ALTERED_SEARCH_PATH flag if you can construct a full path to your DLL or use the SetDllDirectory function to add a directory to the search path.
要手动将您的路径永久添加到 Windows PATH(永久=直到您删除它),请右键单击我的电脑>属性>高级>环境变量>系统变量>路径>编辑>变量值,添加一个分号(这意味着“此外之前的所有内容”)并粘贴 dll 的完整路径。
每次在当前目录中找不到某些内容时,Windows 都会搜索该路径。
To manually, permanently add your path to Windows PATH (permanently = until you remove it), right click My Computer>Properties>Advanced>Environment Variables>System Variables>Path>Edit>Variable Value, add a semicolon (which means "in addition to all before") and paste the full path of your dll.
Windows will search the path every time it can't find something in the current directory.
来自: http://msdn.microsoft.com/en-us/library/7d83bc18 .aspx
From: http://msdn.microsoft.com/en-us/library/7d83bc18.aspx