How to build a portable program by visual studio - visual-studio-2010

I am using visual studio 2010 under Win7-64bit to build an application with openCV. I finished development and build the release version without error. I also successfully run the program in debug mode. I then move the .exe file to other directory in the same computer. I run it in cmd.exe and I got error warning: Error opening file <../../modules/highgui/src/cap_ffmpeg_implhpp:537>
I guess there are some dependence with some libraries of openCV but I don't how to solve it. My final task is that I can use that .exe in another computer under Win7 directly. How to do it?
I found a similar question here. But I don't have .dll file built, so what should I do to solve this problem?

Building an OpenCV app with shared libs (DLLs) require the DLLs to be available (same folder or in lookup path) to the exe when it is run.
If you are using static linking then you don't need any of the OpenCV DLLs to be reachable. However, due to licensing issues, ffmpeg is linked dynamically even when the rest of the libs are linked statically, and thus, you need to have the ffmpeg DLL available for the exe. It is called something like opencv_ffmpeg*.dll.
Note that this is only needed if you are using highgui related functionality.

Related

Cannot find or open PDB File error when running the program even though it builds successfully

I have a project in visual c++ where I am referring some external DLL.
I have already included the lib directory in linker section and mention it in the input section of the linker and also included the same in c/c++ General Additional Include Directories section.
Thus the project compiles successfully but whenever I try to run it; it fails with an error "Application was unable to start correctly" but if I see the output section it seems everything is loaded correctly but against that particular Dll it says that "Cannot find or open the PDB file".
How to fix this error so that I can run my program. It is an MFC program running in Visual Studio 2010.
when I run the program through the Dependency Walker, most of the API-MS-WIN-CORE-HEAP, FILE, and EXT-MS-WIN-SESSION USERMGR -l1-1-0.dll many similar to this are unavailable. I even tried to repair the visual studio it didn't work. Is there any idea how to go about it
0x0000007b sounds familiar to me.
Most likely that is due to 32/64 bit library mixture you are linking with.
Either you are building for x64 and linking with a win32 external library or vice versa.
In your Visual Studio project settings separately configure platform architectures you are compiling for and then you can choose the profile which you are actually compiling for.

Portable installation for windows desktop app compiled with msvc 2015

Recently I switched from mingw to msvc compiler for my Qt app.
I am using Qt5.8. The msvc debugger is from the windows 10 kit (though I develop on Win7 and Win8.1) and the compiler from the vc++2015 build tools.
I can run the app locally, but I can't run it on a different, clean computer.
I know that I have to copy the compiler specific dll's to the application's executable directory. All the other dlls are found by windeployqt. Still I don't get it to work. I can't ship vc_redist packages the user has to install, due to the requirement to be able to load the app from a pendrive. On the dev machine there are several dlls of the same name, how can I figure out which ones are actually used by the compiled app?
Questionable dlls is especially api-ms-win-crt-runtime-l1-1-0.dll.
On the deployment I got those errors:
I also tried Dependency Walker and showed the full paths. I assume the first hierarchy level is the important one, that's why I've hidden deeper hierarchies. I am wondering why the full path shows the dir System32 because isn't this the 64-bit files folder?? I did not target any specific one but my app must be running on x86. Is this a misunderstanding?
EDIT
According to another question and this Microsoft blog update it worked for me when I additionally included all dlls from this folder C:\Program Files (x86)\Windows Kits\10\Redist\ucrt\DLLs\x86. There is also a file named ucrtbase.dll. I have no idea why DependencyWalker showed different ones.
You can use tools such as Dependency Walker to see which DLL is used by any other DLL or exe file.
Edit: You can also take a look at Determining Which DLLs to Redistribute on MSDN
Also you could use static linkage to link against the MSVC runtime (i.e use /MT switch instead of /MD (see https://msdn.microsoft.com/en-US/library/2kzt1wy3.aspx). However this would also mean rebuilding Qt, but it would also give you the opportunity to build a static version of Qt, meaning that you would not need to ship any DLL alongside your exe. You can find more info on Qt wiki: Build Standalone Qt Application for Windows

Create a completely .exe with opencv in Visual Studio

I was creating a project in Visual Studio with OpenCV and it runs fine. But I cannot just run the compiled .exe file to another computer. Because it does not have opencv or c++. So please help me on how to create an installer program so that the computer does not have to install opencv or c++ and running the project?
Just use Dependency Walker tool to find dlls your program depends on. Find the dlls on your system, and copy them to your program distribution (to folder that contains executable file).

System.IO.FileNotFoundException when trying to load DLL

I'm not a a very experienced Windows developer, so I hope this all makes sense.
I created a Managed Assembly DLL using Visual Studio 2010. The DLL (Plip.dll) contains a C++ class that is using System.IO.SerialPort class to do some simple communication over a serial port.
In a second Visual Studio project I created a simple GUI that uses the class found in Plip.dll. In my GUI project I have the line : #using "Plip.dll" . In the Project Properties I set the 'Resolve #using References' value to the correct location of Plip.dll. The GUI builds just fine. If I copy the GUI.exe and Plip.dll to the same folder, the GUI runs just fine on my computer.
The problem I am having is that when I copy both files to a second computer, I cannot get the GUI executable to run. I get the following error : "System.IO.FileNotFoundException. Could not load file or assembly "Plip.dll" Vesion=.... ". I get this error even though both the exe and dll are located in the same folder.
Any suggestions on how to resolve this issue? Is there some option I need to set in my GUI project to load the DLL correctly at run time?
I suppose the problem is not the Plip.dll, but it's dependencies.
Use Dependency Walker on the second computer to see if it needs any other dll's (they might be installed in System folder or in %PATH% on your development computer, but not on the other).
If this second computer doesn't have Visual Studio installed, you are probably missing Microsoft Visual C++ 2010 Redistributable Package (you need to install it on the other computer)
Also make sure that you compile in Release because debug builds need debug dependencies.
I found the answer to this problem to be much simpler than Dependency Walker (but admittedly, that was fun to look at).
In my case, the issue was a mis-match between the .DotNet versions in the DLL and with the application's .net version. This was caused by building the "class library" using .DotNet 6.0 (dot net core?).
Instead, the entire class needed to be re-built using "Class Library (.NET Framework)"
enter image description here
I wrote an article on this problem.
https://keyliner.blogspot.com/2022/09/visual-studio-c-linked-dll-exception.html

Adding libraries to Visual Studio problem

Can someone link me a good guide for using libraries in a c or c++ project?
Right now I'm trying to add OpenCV to a newly created project. I've added all the directories I can think of in "Project and Solutions -> VC++ Directories" and to make sure I've dragged and dropped all the .lib and .dll files into the project.
The project builds but when I run the simple "Hello, World program" it gives me this error message:
"cv.exe unable to locate component.
This application has failed to start because cv200.dll was not found. Re-installing the application may fix this problem."
How can I really add this cv200.dll? I've dragged&dropped it into the project..
Thanks!
You need to make sure that cv200.dll is in the DLL search path at run time. The easiest way to do this is to put it in the same directory as the built executable. Dragging and dropping a DLL or LIB file into your project has no effect.
MSDN has a good description of the full DLL search order when loading libraries at runtime.
By default during installation OpenCV create env. variable path \bin.
All dll assumed to be in that dir. However you are using OpenCV 2.0, and OpenCV 2.0 installation doesn't include lib and dll files for Visual Studio. You seems already built all dll's and lib's. If you installed OpenCV correctly just move all dll's into \bin (for example C:\Program Files\OpenCV\bin)
If for some reason you are missing some dll or libs here is instruction how to build them
http://mirror2image.wordpress.com/2009/10/20/switching-to-opencv-2-0-with-vs2005/

Resources