openCV program compiles but crashes on run - c++

I just started using openCV (version 2.4.1) in visual studio 2008 on windows 7. I did the installation and the "hello world" program as described in
http://opencv.willowgarage.com/wiki/VisualC%2B%2B
and
How to install OpenCV 2.0 on win32
Thanks to these instruction my program compiles fine without any errors. But when I first ran it I got error that files opencv_core241d.dll and tbb_debug.dll are missing. So obviously something didn't get set right but as per the instruction in first link I copied these files to the same folder where the exe is sitting, Ran it third time and now I am getting the popup about libgcc_s_dw2-1.dll missing. I have done a search on my computer and no such dll is available.
I have researched this online and haven't seen any real solution online about some issues like this. My guess is with the multiple dll being missing openCV didn;t get installed properly but I have no idea what really is going on.
Any help is desperately needed and will be appreciated heavily by my hairs and scalp.

Follow these steps and try.
Extract OpenCV 2.4.x into your main partition (I'll assume C\{opencvdir})
Add C\{opencvdir}\build\x86\vc9\bin to environmental variable's path variable. And restart your computer (These settings are for 32bit (x86) Windows version and Visual Studio 2008 (VC9)).
Now create a new Visual Studio project and add your sample OpenCV code.
Go to project Properties -> Configuration Properties -> C/C++ -> General -> Additional Directories and add:
"C\{opencvdir}\include";
"C\{opencvdir}\include\opencv";
"C\{opencvdir}\include\opencv2"
Go to project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies and add:
"C\{opencvdir}\build\x86\vc9\lib\opencv_core240.lib";
"C\{opencvdir}\build\x86\vc9\lib\opencv_highgui240.lib";
"C\{opencvdir}\build\x86\vc9\lib\opencv_imgproc240.lib";
"C\{opencvdir}\build\x86\vc9\lib\opencv_video240.lib"
(These libraries are for a basic application. Add more as your application needs them).
Now run your project.
P.S. My recommendation is to use Visual Studio 2010 with OpenCV 2.3.x or higher.

Related

Cannot open source file in a CMake Project in Visual Studio

I have a C++ Project in Visual Studio 2022 (Windows 11) that is put together using CMake. I understand that the difference here is, that my project is not a Solution but rather just folders with code and the CMake tells it how to compile it?
But my problem is, that it doesn't seem to find C's standard libraries and shows error "cannot open sourcefile".
Screenshot
The error is definitely not in the project, since it runs just fine on my laptop, just not on the PC I want it to run on.
How can I tell it where these libraries are? Where are they located even?
Any help would be greatly appreciated and I can share more files on request.
Things I have tried:
Going to properties and choose the correct Windows SDK Version - The properties are empty
Comparing every variable of the CMake Settings with the ones on my laptop where it works
completely reinstalling Visual Studio (yes I did that)
looking through lots of StackOverflow questions but none of them describe my problem

Can't Build PortAudio - "LNK1104: cannot open file 'ksguid.lib'"

I'm a beginner in C/C++, so please bear with me.
I'm trying to build the PortAudio library so I can use it in one of my project. I'm using VS 2013, the preset project-file for builds had to be converted to my version. I've been able to fix all the many problems that occurred on my long way here, except one:
LINK : fatal error LNK1104: cannot open file 'ksguid.lib'
I've seen this and this site. All of them address exactly this problem, yet non of them has been able to solve it. Here are the solutions these sites suggest:
Add WASAPI - symbol to portaudio.def,
Add PA_WDMKS_NO_KSGUID_LIB - definition to the preprocessor
You can get the ksguid.lib-file from the Windows 7 SDK. It might even already be installed on your computer. It's best to use the explorer to find it (probably C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64).
When you found it, go back to Visual Studio and go to Project > Properties > Configuration-Properties > Linker > Input, then click on the little arrow on the right of Additional Dependencies and choose edit:
Enter the absolute filepath to ksguid.lib. Make sure that you surrounded it with "-s and that you put a ; at the end. (Throws an error without a usable description otherwise - Microsoft as we know it.)
Source: Bitbucket, stackoverflow
ksguid.lib is included in the Windows 7, 8, 8.1, and windows 10 sdk. The answer provided by #Nearoo is perfectly valid. This alternative answer involves modifying what directories the portaudio Visual Studio project looks for library files.
For reference, I'm using Visual Studio 2013 on a Windows 8.1 PC.
Navigate to: Project -> Properties -> VC++ Directories
At the top of the window,
change Configuration to "All Configurations".
change Platform to "All Platforms"
In the "Library Directories" portion, add the following path:
$(WindowsSdkDir)\Lib\winv6.3\km\$(PlatformTarget)\
This nice thing is that this one path uses macros so it will work with Debug, Release, 32 bit and 64 bit builds of portaudio.

cpp:-1: error: C1041: cannot open program database; untitled-build-desktop-debug\vc120.pdb'

All the answers available for this problem are solutions for Visual studio. I am facing this problem in QT. I run a sample example but this error pops up.Could somebody help.
error: C1041: cannot open program database 'c:\users\newfolder\untitled-build-desktop-debug\vc120.pdb'; if multiple CL.EXE write to the same .PDB file, please use /FS
right click on project-> properties->c/c++ -> output files:
in Program Database File Name: include the project name with path. (.../../../../release/ProjectName/)
This approaches works for me.
(This answer may or may not only apply to those who have built QT from source.)
Ensure you are building with the same Visual Studio toolchain version that your QT distribution was built for.
I got this error when I used a build kit (Options -> Build & Run -> Kits) that was configured to use MSVC 2013 (12.0), but the QT Version was msvc2010_opengl. Apparently the discrepancy led to an invalid build configuration. Modifying the build kit to use VS 2010 fixed the problem.

MSVCP100D.dll missing

When I try to debug my C++ application I get the error
The program can't start because MSVCP100D.dll is missing from your
computer. Try reinstalling the program to fix this problem.
I found someone with a similar problem here: Remote debugging C++ on the Windows Server 2008 platform with VS2010; MSVCP100D.dll missing however the solution given there doesn't seem to show up when I go to the solution properties.
Would reinstalling Visual Studio fix this problem?
Usually you don't want MSVCP100D.dll on your system. It's for debugging purposes only. If you get this error for your release build you must make sure that you didn't accidently add a 'Debug'-tagged Project Output to your setup project.
If you really need to debug your software on a remote machine, I suggest you do the following:
Create a new Setup project called 'CRTDebug100Setup' and add the following Merge Modules (found under C:\Program Files\Common Files\Merge Modules):
Microsoft_VC90_DebugCRT_x86.msm
policy_9_0_Microsoft_VC90_DebugCRT_x86.msm
Build, and deploy on your computer to be debugged!
Reinstalling Visual Studio fixed the problem.
This can also occur if Generate Debug info is not set to No
Configuration Properties -> Linker -> Debugging -> Generate Debug info
Followup on l33t's answer above (tried to revise it but it did not seem to appear).
Added later by gpicher 10 Jan 2012: I believe those .msm packages would be for a 9.x version of the DLL in question, not a 10.x version. I resolved a similar problem I had by making a setup project with Visual Studio 2010 installed on a 64 bit Windows installation, using the merge module Microsoft_VC100_DebugCRT_x86.msm in the folder C:\Program Files (x86)\Common Files\Merge Modules. There's a similar x64 version of the .msm if the application showing the error dialog is a 64 bit application. In this case a third party was providing me a debug build of their application in order to develop and test new plugin code against, so I couldn't change build settings, and wanted the debug functionality.
Find the Visual Studio 2010 install iso file.
Extract cab44.cab file from the ISO.
Then extract file "F_REDIST_DLL_APPLOCAL_msvcp100d_x86" from the .cab file using 7z.
Rename the file to msvcp100d.dll.
For x64 version. The cab file name is cab26.cab and the file name is F_REDIST_DLL_APPLOCAL_msvcp100d_x64.
For similar issue such missing msvcr*d.dll for another visual studio version. Here is the way I used to find the answer:
Find the Visual Studio ISO.
Extract all the .cab file.
7z.exe t *.cab > filelist.txt
gvim filelist.txt
searching for the interested file name. Hope this helps.

Building an OpenCV application with Visual Studio 2008 and running it from another computer

I've made a simple OpenCV application with Visual Studio 2008 and I've built it in both release mode and debug mode.It works fine from my computer but when I try to run it from another computer which doesn't have OpenCV installed or has another version of Visual Studio with OpenCV it doesn't work.
How can I make the app work from a computer which doesn't have either Visual Studio or OpenCV installed ?
I'm thinking to add the external dependencies ( lib's and dll's ) into the app's folder, change the path in Visual Studio and rebuild it.
Thanks in advance and sorry for the ultranoobish question :)
You don't need to distribute the libs; those are just needed for building the executable.
Just copy the dlls somewhere where the executable can see them (either in the same dir as the exe, or in a dir that's on the system path) and you should be golden.
Copying DLL's with the application or to the path is a good start, but may not be enough. It took me a long time to find out why OpenCV application didn't work on another machine. Visual Studio runtime and OpenMP are used by OpenCV. Those are not installed by default and error messages, if any, are not all that helpful.
You need to build OpenCV and your application with setting (in Visual Studio):
Configuration Properties -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded (/MT)
You need to disable OpenMP support too if that's the problem. Build system changed with OpenCV 2.0. If I remember right, older version had different project files for version without OpenMP.