I'm trying to use a DLL with a Qt project in Visual Studio. Normally to use a DLL, it is put in the program's executable directory. However, after putting the DLL in just about every directory I could think of, it is still not being used by the program. Is there anything extra that I need to do aside from putting the DLL in the executable directory? Thanks.
The dll should be in the working directory of the executable. This is listed under the "Debugging" section of the Project Properties.
Almost all of the Qt plugin directories need to be in a specific folder next to the exe for it to be found (imageformats, platforms, etc).
Another way to find out if you are in the right directory is to add this line to your main.cpp:
#include <QDir>
#include <QDebug>
qDebug() << "Current Directory:" << QDir::currentPath();
Hope that helps.
PS also look at the order of dll search directories for windows. I'll post more later about it. https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx#search_order_for_desktop_applications
Related
I would like to solve this issue once for all, what is the best best to compile a .cpp file that uses windows libraries (to create a exe file).
For instance I have this cpp starting with:
#include "stdafx.h"
#include <Windows.h>
And I get
stdafx.h: No such file or directory
Windows.h: No such file or directory
I know for instance that stdafx require Visual C++ on Windows, but I want to compile it on Linux, how would you do ?
Thanks a lot
The short answer is you cannot build a Windows executable on Linux. But you can download the free Visual Studio Community Edition to build it on Windows.
stdafx.h is a header file in your project. It is used by Visual Studio's pre-compiled headers feature. If you use a predefined project template, Visual Studio will auto-generate stdafx.h and mark it for pre-compilation. You then include the common C++ headers, e.g. STL, in stdafx.h and include stdafx.h in each of your source code files.
When you are not using Visual Studio stdafx.h is a convenient place to pull in the standard headers for runtime libraries but serves no other purpose.
windows.h is the header file for Windows runtime APIs. The Windows APIs and hence the headers are not available on Linux. If you want to build an executable on Linux to run on Linux then you must replace Windows APIs with the Linux equivalents.
I have compiled and build using CMAke and VS 2010. But now I want to try some basic program using MITk library, but I can't find where is the header file, DLL, Lib file? Same as like in OpenCv when we compile and build it, then in install folder we have bin folder that contain DLL file, Lib folder contain lib file and include folder contain header file of CPP program.
So, where is the header file of MITK build library ?
If anybody have idea then suggest to me.
It seems you want to use MITK as a toolkit. As the documentation suggests, you can (must?) use cmake. The generated VS2010 .sln file will handle all the include and library files for you. Use the .bat file if there's one.
There's probably a way to use it without cmake, but I'm pretty sure it's a bad idea.
I am learning how to use OpenCV and as practice I ran a program (in Release mode, x64). I had 0 compiler errors but got a pop-up screen that said:
"the program can't start because opencv_core243.dll is missing"
However, I made sure I declared the correct environment variables and specified the necessary libraries/directories. My problem was fixed when I copied the following .dll files into x64/Release:
opencv_core243.dll
opencv_highgui243.dll
opencv_imgproc243.dll
My program compiles fine now and works. However, I would like to know why. It feels cheap to copy and paste these .dll files. Did I miss a step where these .dll files would be generated automatically?
The actual solution for this problem is to append the path of opencv bin directory to the System PATH environment variable.
Have a look at this answer describing the complete procedure to install OpenCV in Visual Studio 2010.
There is a disadvantage of this approach. The prebuilt OpenCV x86 and x64 binaries have same names. So by appending the path of OpenCV to the PATH variable, you can execute either the 32 bit version or the 64 bit version at a time. To run the other version, you have to change the PATH variable.
An alternative to this, (my personal favorite) also involves copying the dlls to output directory, but this is done automatically at the end of compilation. What I do, is to create new environment variables for x86 and x64 dll paths. I create the User Variables CV_BIN32 and CV_BIN64 containing the paths of x86 and x64 dlls respectively.
After creating the User Variables, open your OpenCV project, go to Project Properties -> Build Events -> Post-Build Event -> Command Line.
Add the copy commands for the dlls you require at the runtime.
This one is for Win32 Release Configuration:
copy "$(CV_BIN32)\opencv_core243.dll" "$(OutDir)"
copy "$(CV_BIN32)\opencv_highgui243.dll" "$(OutDir)"
You can change them for all the 4 configurations, (Debug/Release),(Win32/x64)
Now when the project build procedure completes, the specified dlls will be copied to the output directory automatically, and the error will not be shown.
I've tried all day to get VS2010 to run my program. I can only get the program to find the DLLs if I copy and paste them into the same folder as the output exe.
I have listed the folders containing the DLLs I need included under Linker > General. But running the program still gives me errors such as:
"The program can't start because tbb_debug.dll is missing from your computer. Try reinstalling the program to fix this problem."
What can be going wrong? I am trying to include 2 packages which have VS2010 DLL binaries; TBB (Intel package) and Open-CV (Which comes with both DLLs and LIB files). For the lib files I am also setting them as linker inputs, though the TBB package does not come with vs2010 lib files.
I am entering full paths in the Linker settings, such as: "C:\opencv\build\common\tbb\ia32\vc10", where each folder contains DLL files.
The linker is only looking for .lib files, which "point" the executable to the adresses of the functions in the dll. It has nothing to do where your executable will find the DLLs.
You need to have the DLL either in the directory of the exe - this is default search path, and is the simplest solution.
It gets slightly more complicated if you have different versions of DLLs installed which require side-by-side configuration. Then you need a manifest which tells your exe where to look for the dlls. Then you give the dll to the windows SxS cache.
I'm trying to use OpenCv 2.2 in Visual Studio 2010.
I've configured everything by instruction:
http://opencv.willowgarage.com/wiki/VisualC%2B%2B
and by instruction from the book:
So I've added all /lib and /include paths.
When I build project, it compiles and before starting app, VS displays an error message that opencv_core220d.dll is missing.
This file is in C:/OpenCV2.2/bin as all .dll files. If I add this file to my working directory - it will be fine. Then VS displays error about every .dll file that I added in Linker-Input configuration ( but with .lib extension ).
So, if I add all .dlls file that I've added as .lib in Linker configuration - to my working directory, project will start.
But why? Why VC doesn't see OpenCV2.2/bin folder? Where is this pointed?
Because it doesn't know to look there by default. However, it does know to check the current directory for the DLLs.
You can tell it where to look by adding C:/OpenCV2.2/bin to your Path variable, or if you would rather not muck up your global Path you can set the Environment variable local to the C++ project.
I think that is the syntax for appending to the Path in VS2010, but I'm not sure, so Google it if that doesn't work :)