为什么 Visual Studio 找不到我的 DLL?

发布于 2024-10-17 06:28:55 字数 393 浏览 3 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

惜醉颜 2024-10-24 06:28:55

在项目设置中指定 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.

千秋岁 2024-10-24 06:28:55

我在同一个库中遇到了同样的问题,在这里找到了解决方案
所以:

在 MSDN 中搜索“如何:为项目设置环境变量”。
(这是项目>属性>配置属性>调试
对于那些处于其中的人的“环境”和“合并环境”属性
匆忙。)

语法为 NAME=VALUE 并且可以使用宏(例如,
$(OutDir))。

例如,要将 C:\Windows\Temp 添加到 PATH:

PATH=C:\WINDOWS\Temp;%PATH%

类似地,将 $(TargetDir)\DLLS 附加到 PATH:

PATH=%PATH%;$(TargetDir)\DLLS

多重共线性在这里回答:如何在 Visual Studio 中设置路径?

I've experienced same problem with same lib, found a solution here on
SO:

Search MSDN for "How to: Set Environment Variables for Projects".
(It's Project>Properties>Configuration Properties>Debugging
"Environment" and "Merge Environment" properties for those who are in
a rush.)

The syntax is NAME=VALUE and macros can be used (for example,
$(OutDir)).

For example, to prepend C:\Windows\Temp to the PATH:

PATH=C:\WINDOWS\Temp;%PATH%

Similarly, to append $(TargetDir)\DLLS to the PATH:

PATH=%PATH%;$(TargetDir)\DLLS

(answered by Multicollinearity here: How do I set a path in visual studio?

幸福不弃 2024-10-24 06:28:55

尝试“配置属性 -> 调试 -> 环境”并在运行时设置 PATH 变量

try "configuration properties -> debugging -> environment" and set the PATH variable in run-time

情泪▽动烟 2024-10-24 06:28:55

添加到 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文