Why can't Visual Studio find my DLL?

C++Visual StudioVisual Studio-2010Visual C++Dll

C++ Problem Overview


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?

C++ Solutions


Solution 1 - C++

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.

Solution 2 - C++

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: https://stackoverflow.com/questions/428085/how-do-i-set-a-path-in-visual-studio

Solution 3 - C++

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

Solution 4 - C++

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbrainydexterView Question on Stackoverflow
Solution 1 - C++Cody GrayView Answer on Stackoverflow
Solution 2 - C++OlegView Answer on Stackoverflow
Solution 3 - C++waytofallView Answer on Stackoverflow
Solution 4 - C++may5694View Answer on Stackoverflow