environment variable .. why is that? - visual-studio-2010

I'm using Visual Studio 2010 and I want to code with DLL files.
I adjusted the system environment Path, like C:~~, but execute file can't find DLL files. So I moved the DLL files to c:windows\system32. Then I can use it.
Why can't that find DLL files? I want to know how the computer loads DLL files by using the system environment path.
My path setting is:
%OPENCV_DIR%\bin
(there are DLL files in bin folder)
(OPENCV_DIR = C:\opencv\build\x86\vc10)
and i'm testing Opencv

Related

Access ProgramFilesFolder from Visual Studio post-build events

When building a C# project in Visual Studio, in the post-build events I need to call a program that is situated in C:\Program Files\\MyProgram.exe. How can I access the "C:\Program Files" folder from the post-build events?
At this link: http://msdn.microsoft.com/en-us/library/42x5kfw4.aspx there are several Macros that can be used in the post-build events section of Visual Studio. Is there a Macro or is there a way to access the default ProgramFilesFolder path?
Don't look for a macro, none is provided since you can also use environment variables in the pre/post-build steps. Just like you can with a .bat file, which is the way these build steps actually execute. You are probably looking for the %programfiles% environment variable. So to run that program, simply use:
"%programfiles%\myprogram.exe"
Sadly, using %programfiles% leads to the x86 program files folder. There's an environment variable for x86 program files folder (%programfiles(x86)%) but none for the x64 folder. Thus, you can't target the x64 program files folder, neither explicitly nor implicitly, when using standard environment variables. You'll always target the x86 folder. (vs2019 professional 16.10.1)

Visual Studios 2010 the program can't start because opencv_core243.dll is missing

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.

VS2010 can never find my DLLs

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.

Visual Studio 2010 can't see /bin library of OpenCV

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

How to package stand alone exe inside Visual Studio Installer maker?

Im currently using Visual Studio Installer to package my dll program. How to include stand alone executable program inside my installer project? Since my dll is using the exe(s) in order to run.
Note: For my development platform, I already have the exe(s) inside my c:\ directory. So I would like my installer to also copy the exe(s) to c: drive of other user's platform when they run my installer.
Add the required exe during making the installer to the Application Folder.
Then change all the path that points to those required exe(s) so that it points to the exe(s) in the Application Folder. Shown below:
Instead of "C:\directory\file.exe" to Application.StartupPath & "\file.exe"
Application.StartupPath returns the path of the executable file that started the application.
So if you app is installed in "C:\Program Files\MyApp\program.exe" this would return "C:\Program Files\MyApp"
I hope this helps.

Resources