How do I set the path to a DLL file in Visual Studio?

Visual StudioVisual C++Dll

Visual Studio Problem Overview


I developed an application that depends on a DLL file. When I debug my application, the applicationwould complain that:

> "This application has failed to start because xxx.dll was not found."

So I have to copy the DLL file into the same directory as my .vcproj file.

Is there a way to set the project to look for the DLL file in (preferably) some relative path or (not preferred) some absolute path?

Similar concept to how we set include and library path in the project settings.

I mean when I debug my application (hitting F5) the above error would pop up.

Visual Studio Solutions


Solution 1 - Visual Studio

  1. Go to project properties (Alt+F7)
  2. Under Debugging, look to the right
  3. There's an Environment field.
  4. Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending PATH=%PATH%;$(ProjectDir)\some-framework\lib or prepending to the path PATH=C:\some-framework\lib;%PATH%
  5. Hit F5 (debug) again and it should work.

Solution 2 - Visual Studio

Go through project properties -> Reference Paths

Then add folder with DLL's

Solution 3 - Visual Studio

The search path that the loader uses when you call LoadLibrary() can be altered by using the SetDllDirectory() function. So you could just call this and add the path to your dependency before you load it.

See also DLL Search Order.

Solution 4 - Visual Studio

Another possibility would be to set the Working Directory under the debugging options to be the directory that has that DLL.

Edit: I was going to mention using a batch file to start Visual Studio (and set the PATH variable in the batch file). So then did a bit of searching and see that this exact same question was asked not long ago in this post. The answer suggests the batch file option as well as project settings that apparently may do the job (I did not test it).

Solution 5 - Visual Studio

In your Project properties(Right click on project, click on property button) ▶ Configuration Properties ▶ Build Events ▶ Post Build Events ▶ Command Line.

Edit and add one instruction to command line. for example copy botan.dll from source path to location where is being executed the program.

copy /Y "$(SolutionDir)ProjectDirs\x64\Botan\lib\botan.dll" "$(TargetDir)"

Project Properties

Solution 6 - Visual Studio

I had the same problem and my problem had nothing to do with paths. One of my dll-s was written in c++ and it turnes out that if your visual studio doesn't know how to open a dll file it will say that it did not find it. What i did was locate which dll it did not find, than searched for that dll in my directories and opened it in a separate visual studio window. When trying to navigate through Solution explorer of that project, visual studio said that it cannot show what is inside and that i need some extra extensions, so that it can open those files. Surely enough, after installing the recomended extension (in my case something to do with c++) the

> "This application has failed to start because xxx.dll was not found."

error miraculously dissapeared.

Solution 7 - Visual Studio

I know this question had been answered years ago, but for those like me who needed to change where the debugger starts the application, change the command property under Project Properties -> Debugging.

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
QuestionsivabudhView Question on Stackoverflow
Solution 1 - Visual StudiosivabudhView Answer on Stackoverflow
Solution 2 - Visual Studiokravits88View Answer on Stackoverflow
Solution 3 - Visual Studioi_am_jorfView Answer on Stackoverflow
Solution 4 - Visual StudioMark WilkinsView Answer on Stackoverflow
Solution 5 - Visual StudioJomaView Answer on Stackoverflow
Solution 6 - Visual StudiodinozaverView Answer on Stackoverflow
Solution 7 - Visual StudioTheOriginalColeView Answer on Stackoverflow