views:

207

answers:

4

I developed an application that depends on a dll. When I debug my app, the app would complain that "This application has failed to start because xxx.dll was not found."

So what I have to do is to copy the dll into the same directory as my .vcproj.

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

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

EDIT: Sorry for all the confusion: I meant when I debug my app (hitting F5) the above error would pop up.

A: 

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).

Mark Wilkins
what if I depend on 2 dlls, each one lives in its own directory? (i simplified my question above)
ShaChris23
I don't think it would be possible to make this solution work for more than a single directory.
Mark Wilkins
A: 

Add the DLL as a reference to your project. In the "Reference Properties," set the property "Copy Local" to True.

Black Frog
+1  A: 
  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
  5. Hit F5 (debug) again and it should work.
ShaChris23
A: 

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.

jeffamaphone