DLL's dependency cannot be found when DLL moved to another location - c++

I'm on Windows 10, Visual Studio 2017, x64 build . . .
I have a DLL that I'm using in an exe project. We'll call it, myLibrary.dll. It comes with a .lib companion file as well. The myLibrary.dll has some other DLL dependencies that it is using. We'll call that one theDependency.dll.
I've linked the companion myLibrary.lib file in my project through Linker --> General --> Additional Library Dependencies properties. Added myLibrary.lib to the Additional Dependencies.
When I build my project, I use post build event to copy the myLibrary.dll to the Release/Debug directory of my project.
This works fine.
My issue is when I try to use myLibrary.dll in a different exe project. I get an error that it cannot find the theDependency.dll. I've used all the same property setup as the first exe project. As a test, I moved the build directory of the first exe project to another location (on the same computer) and I get the same error. "Cannot find theDependency.dll"
How is myLibrary.dll targeting it's dependencies? Not sure why the 2nd project gets this error? Also, not sure why moving the files gets this error?
Any ideas? Thanks.

Adding the path of the dll to the PATH environment variable worked for me.

Related

visual studio c++ project cannot find .dll

I have downloaded the Autodesk fbx sdk and trying to build a simple console app. I have added additional directories in Linker / General / Additional Library Directories like follows:
see the screenshot of the directory below. There are several libs that (I suppose) I should add in dependencies, and there's also the .dll file. It's release folder (debug is another available), for x86 architecture and for VS2017 which I am using.
Also, I have add dependencies like below and have included the standard include folder as specified in the Autodesk manual
The project builds fine but shows the following when run:
Cannot run code because libfbxsdk.dll could not be found...
But it is in the folder as you can see in the pic. Could you pls help?
The linker settings have nothing to do with finding DLL files at run-time. If you want this SDK to be available to all programs - which without reason to do otherwise would be my recommendation - hit the start button and search for "environment", choosing "Edit environment variables for your account". Edit the value of the PATH environment variable (adding it if necessary) to include the directories where the DLLs are located.
If you only want it to be available to this particualr program (and you don't have any other custom DLLs that need to be found) you could also change the startup directory in the project properties to the directory where the DLL files can be found (the startup directory is one of the locations in the system search path).

Getting dll include to work in Visual Studio

I am new to Visual Studio, and to using .dlls, and I am trying to get portaudio running, but have not had success.
I built the .dll file, and created a console application project in VS,
I added the portaudio .lib file to "Additional Dependencies" in the solution properties -> linker -> input options.
I then added the directory for portaudio.h to VC++ Directories --> "Include Directories"
After those steps, I was able to build example code without errors, but when I run the program I would get this error:
The program can't start because portaudio_x86.dll is missing from your computer. Try reinstalling the program to fix this problem.
I tried adding the directory to where the dll and lib files are to "Executable Directories" but still I get the same error.
I don't know what else I need to do to get the dll working in VS. Any help is much appreciated.
The easiest solution is to move the created DLL to the same directory where your executable is running. There is no need to make project setting changes.
The other solution is to move the DLL to a directory specified in your PATH statement, or will be found by Windows using the Dynamic Link Library Search Order criteria.

Adding my DLL into a Visual Studio project in C++

I am working on a project that involves making a dynamic link library, so I want to test it in a console app in Visual Studio.
The DLL is also made in Visual Studio, it doesn't have much, just a few functions in it. I'm not sure if I'm just supposed to include the librarys header in the include directories panel in Properties, or do something else
A lot of people say I'm supposed to add its corresponding .lib file in the Library or Reference directory, but I'm not sure that VS generates a .lib file alongside the DLL. I'm using VS 2015.
I don't have VS in front of me this very moment, but these should be the general steps to set it up:
Properties->Linker->Input: your.lib
Properties->Linker->Additional Library Directories: ../your/bin
Properties->General->Compiler->Additional Include Directories: ../your/include
To build your app, the DLL's API headers must be in the include for the compile-time, it's LIB files in the bin for the link-time. Once you have your app EXE, all you need is the DLL to be in the same folder as your EXE when it executes.
You might also want to add the dll project and the app project into a common solution in VS and add (right click) Project Dependency from the app to the dll. This ensures correct order of building, assuming you are going to build the dll at all.
You can also do what I did.
You can create a Libs directory inside of your Solution directory.
You can then place your .DLL files inside of the Libs directory or some sub-directory inside of Libs
In my case, I added the entire SFML-2.3.2 directory in there, which included the source-code, .lib files, and .dll files.
I did link up what I could in the project properties, but I used Visual Studio's macros to fill in the path name to the Solution directory. Just in case I wanted to put this in version control and work on it from multiple machines.
Then I opened up the Project's Property Page.
Within the property page, I went to Build Events -> Post-Build Event -> Command Line
Within the Command Line, you can add a copy command that will copy any needed files into the same directory as the executable that will need them.
In my case I used: copy "$(SolutionDir)Libs\SFML-2.3.2\bin\*" "$(TargetDir)"
I could have written multiple commands to copy just the individual files that I needed, but I had spent a good three hours trying to get SFML to work without actually installing it.

dll is missing when running executable (libcurl)

I believe I have followed every instructions given, so I just have to ask the same question again.
I am trying to use libcurl.
I have changed the following settings in my project:
Configuation Properties|VC++ Directories|Library Directories - here I have put the folder where the .lib file is found. I did this for Debug, Release and All Configurations.
Configuation Properties|VC++ Directories|Include Directories - here I have put the folder where the .h files are found. I did this for Debug, Release and All Configurations.
Configuration Properties|Linker|Input|Additional Dependencies - I have added the .lib file. I did this for Release, Debug and All Configurations.
Configuration Properties|Linker|General|Additional Library Directories- I have added the folder where the .lib file is located. I did this for Release, Debug and All Configurations.
The program builds well without any errors.
When running the .exe file, I get the error message:
.dll is missing from your computer.
I have put the .lib file in the same folder as the .exe file, but that does not help. In fact I have put the .lib file in all folders for my project, but the computer can't find them anyway.
How can this be explained?
Is it possible to build the program without errors if the .lib file is simply wrong? I use a win32 .lib file and I create a Win32 project, but I'm running on a Win64 PC. Does that matter?
Desperate for help. Been searching like crazy for three days now.
Bests,
You have to put the "libcurl.dll" in the same folder as your executable (DEBUG or RELEASE). In case of debugging, the dll is expected in your Project folder because Visual Studio is setting that directory. The ".lib" file is only necessary on compile time, which is already successful in your case.
The DLL comes with the cURL Projekt or is build when building the lib. Usually you will find the DLL near the directory of the lib. Search for a "bin" folder.
If you use the 32 bit version, make sure that you use the 32 Version of the DLL. The DLL has to match with the EXE, not with the OS.

How to include required dll to a mvc c++ build

I have a project that relies on some other projects on my solution. For example assume that my main project is m and it produce m.exe
This project depends on some other projects say a.dll, b.dll,c.dll.
My problem is:
when I build m.exe, a.dll,b.dll and c.dll are created and the output is placed in some directory on my pc, but these dlls are not copied to output directory of m.exe and hence when I want to debug m.exe, they are not found.
If I copied them to output directory (debug directory) the application runs, but I am not able to debug into a.dll,b.dll and c.dll.
How can setup my MSVC so I can compile and debug into these dlls?
I am using Visual studio 2012.
In your project settings (Configuration Settings -> General) for each project, you can set the output directory. Change it for every configuration/platform of every project to e.g. $(SolutionDir)$(Platform)\$(Configuration)\ (or anything else that resolves to the same location for each project).
The alternatives are to either add a post-build step to copy files around via command, or to change your DLL resolution mechanism and use delay loading code that resolves referenced DLLs "manually".