为什么 Visual Studio 找不到我的 DLL?
在 Visual Studio 2010 中,在 VC++ 目录 > 下可执行目录
,我已经指定了glew32d.dll
的路径。但是,当我运行可执行文件时,它仍然抱怨。
另一方面,如果我将 DLL 复制到本地文件夹并运行可执行文件,则它不会抱怨。
有人可以告诉我如何解决这个问题吗?另外,为什么 Visual Studio 无法识别该路径?
更新 场景:我目前使用一个模板项目,将其用作许多项目的起始代码。该模板依赖于glew32d.dll。我通常将所有依赖的 dll 存储在一个公共 bin 文件夹中。我希望引用这个文件夹,Visual Studio 可以从那里读取 dll,而不必每次都复制 dll。处理这个问题的好方法是什么?
In Visual Studio 2010, under VC++ Directories > Executable Directories
, I have specified the path to glew32d.dll
. However, when I run the executable, it still complains.
On the other hand, if I copy the DLL into the local folder and run the executable then, it doesn't complain.
Can someone please tell me how to fix this? Also, why is Visual Studio not recognizing that path?
Update
Scenario: I currently use a template project which I use as a starter code for a lot of my projects. This template depends on glew32d.dll. I usually store all dependent dlls in a common bin folder. I was hoping to reference this folder and Visual studio could read the dlls from there, instead of me having to copy the dlls everytime. What would be a good way to handle this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在项目设置中指定 DLL 文件的路径并不能确保应用程序在运行时找到 DLL。您只告诉 Visual Studio 如何查找它需要的文件。这与程序构建后如何找到它需要的内容无关。
将 DLL 文件放入与可执行文件相同的文件夹中是迄今为止最简单的解决方案。这是依赖项的默认搜索路径,因此您无需如果你走那条路,做一些特别的事情。
为了避免每次都手动执行此操作,您可以为项目创建一个构建后事件,该事件会在构建完成后自动将 DLL 复制到适当的目录中。
或者,您可以将 DLL 部署到 Windows 并排缓存,并将清单添加到指定位置的应用程序。
Specifying the path to the DLL file in your project's settings does not ensure that your application will find the DLL at run-time. You only told Visual Studio how to find the files it needs. That has nothing to do with how the program finds what it needs, once built.
Placing the DLL file into the same folder as the executable is by far the simplest solution. That's the default search path for dependencies, so you won't need to do anything special if you go that route.
To avoid having to do this manually each time, you can create a Post-Build Event for your project that will automatically copy the DLL into the appropriate directory after a build completes.
Alternatively, you could deploy the DLL to the Windows side-by-side cache, and add a manifest to your application that specifies the location.
我在同一个库中遇到了同样的问题,在这里找到了解决方案
所以:
多重共线性在这里回答:如何在 Visual Studio 中设置路径?
I've experienced same problem with same lib, found a solution here on
SO:
(answered by Multicollinearity here: How do I set a path in visual studio?
尝试“配置属性 -> 调试 -> 环境”并在运行时设置 PATH 变量
try "configuration properties -> debugging -> environment" and set the PATH variable in run-time
添加到 Oleg 的答案:
通过将 Visual Studio 的
$(ExecutablePath)
附加到“配置属性”->“调试”中的 PATH 环境变量,我能够在运行时找到 DLL。该宏正是在“配置属性”->“VC++ 目录”->“可执行目录”字段* 中定义的,因此,如果您有该设置来指向所需的任何 DLL,只需将其添加到您的 PATH 即可轻松在运行时查找 DLL !* 我实际上不知道
$(ExecutablePath)
宏是否使用项目的可执行目录设置或全局属性页的可执行目录设置。由于我经常使用的所有库都通过属性页进行配置,因此这些目录显示为我创建的任何新项目的默认目录。To add to Oleg's answer:
I was able to find the DLL at runtime by appending Visual Studio's
$(ExecutablePath)
to the PATH environment variable in Configuration Properties->Debugging. This macro is exactly what's defined in the Configuration Properties->VC++ Directories->Executable Directories field*, so if you have that setup to point to any DLLs you need, simply adding this to your PATH makes finding the DLLs at runtime easy!* I actually don't know if the
$(ExecutablePath)
macro uses the project's Executable Directories setting or the global Property Pages' Executable Directories setting. Since I have all of my libraries that I often use configured through the Property Pages, these directories show up as defaults for any new projects I create.