I built an OpenCV project in C++ visual studio 2019 using static library, but still needs dll file at the run time - c++

I built an OpenCV project in C++ visual studio 2019 using static library:
I made path to the lib file and also set Runtime Library (in project properties--> C\C++--> code generation) as Multi-Threaded/MT. Project is in Release mode.
Also I made similar to the following video:
https://www.youtube.com/watch?v=or1dAmUO8k0

Yes, you also need to set these dlls into system environment variables. The dlls are from [OpenCVInstallation]\build\x64\vc15\bin and OpenCVInstallation\build\bin, which is like:
the image

Related

How to set dependency DLL paths in Visual Studio?

I am working with Cyclone DDS, and they have two builds,
c build (contains multiple files in the bin folder)
and c++ build (contains DLL file in the bin)
after Cyclones DDS installation, I have to set these bin paths in system environment variables.
how can I avoid this? I need to set them in the visual studio 2017 itself. without setting paths in the system environment
or can I copy bin files into my project directory? so that I can use the project file on any PC which has visual studio 2017 without reinstalling CycloneDDS?
Windows by default will prefer .DLL files in the same directory as the .EXE. So while developing, you can put them in your Visual Studio Debug and Release folders. For other people, you include the DLL's in the installer.
The exception is the *140.dll stuff, for which you need the Visual C++ redistributable. That's installed as part of Visual Studio 2017, but can also be distributed independently (hence the name).

Is the visual studio release mode exe file standalone or not?

I want to build a single standalone executable file for a windows console application built in Visual Studio 2019. By standalone, I mean that I want a single exe file that I can move to any location on any computer and it will still run without extra files surrounding it (no dependencies).
For the life of me, I can't find a clear answer anywhere.
Question 1: Is the visual studio "release" executable file standalone?
Question 2: How do I make a standalone exe file that will run anywhere, no matter what libraries my code depends on?
Question 3: Can this be done inside visual studio, or do I need other software to do it?
You could use Microsoft Visual Studio Installer to deploy a Visual C++ Application.
For third-party libraries, you could select static linking version. If there is no static link version and only dll, copy the corresponding dll together when publishing.
For the c++ runtime library, select the static compilation method: Properties->C/C++->Code Generation->Runtime Library->Multi-threaded (/MT).
Also, you could use depends.exe (a Microsoft small tool) to view the dll, and then package it together.

how to deploy simple boost program written in visual studio on other computers

I have written a simple program in C++ that uses the boost filesystem library to organize some files. I am using the Visual Studio 2013 Express for Windows Desktop IDE. I would like my program to run on other computers without an installer or anything else. The user should be able to just download the program and click on it.
I built my program in Release mode and it works on my computer. When I tried to deploy on another computer, the error I got was MSVCP120.dll is missing. To fix this I right-clicked on my project, clicked properties, then Configuration Properties > C/C++ > Code Generation, and I changed the Runtime Library from Multi-threaded DLL (/MD) to Multi-threaded (/MT). Now my program won't compile properly because of this build error:
Error 1 error LNK1104: cannot open file
'libboost_filesystem-vc120-mt-s-1_55.lib' C:\Users\inspection\Desktop\sortFile\Project1\Project1\LINK Project1
I looked in the following folder:
C:\Program Files\boost\boost_1_55_0\libs\filesystem\build\msvc-12.0\release\link-static\threading-multi
and I could not find libboost_filesystem-vc120-mt-s-1_55.lib, though I could find libboost_filesystem-vc120-mt-1_55.lib. The file names are close, they only differ by an '-s' term located after the '-mt' term.
How can I statically link the boost filesystem library so that my whole program runs as a standalone executable, without another user having to install anything?
Boost needs to be recompiled to match your new runtime library setting. The filename of the Boost library indicates the settings it was linked with, and the Boost auto-link code automatically updated the needed filename to match your new settings. In this case, it quite accurately indicates that you need a Boost lib which was compiled with a static stdlib link.

How to link opencv and other dll files to output exe of visual studio 2013

I am new with visual studio, opencv.
I am using visual studio 2013, opencv and c++ for my project.
I configured (copied path) the opencv and other library to my computer environment system.
After run the project in visual studio, normally, there will be an exe file in the project.
I can copy the exe file in the project folder and copy to other place in my computer and it will run normally.
This is because my computer environment systems are configured with opencv and other library.
I want to do the same thing with other computers BUT I do not want to manually configure each computer with opencv and other libraries.
Are there any ways that I can do to link everythings all in exe file after run the project in visual studio 2013 so that I can run the exe without depend on the path of libaries and opencv?
EDITED
I use opencv installer opencv2.4.7.exe
In the current VS2013 my project, i configured my project and opencv installer as this link
http://www.anlak.com/using-opencv-2-4-x-with-visual-studio-2010-tutorial/
question : Can i use the library in folder C:\opencv\build\x64\vc11\staticlib come from the opencv installer no need create my own library from source opencv?
question : In case i need to generate new library from opencv source (http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html) or use lib in static folder of opencv installer, if i want to include it all to exe files, do i need to create new project and reconfigure?
Thank you.
First you need to rebuild openCV to generate static libraries instead of dynamically linked ones. This way all code that your application uses is thrown together in one single exe-file (which will probably be significantly bigger). This exe-file you can move to other computers and they should still work there, provided they have an architecture that is at least compatible with yours. So if you build it on an x86 perconal computer (32-bit), it should basically work on any other personal computer. If you build it on a x64 computer (AMD 64-bit), it will only run on other x64 machines. At least this is true assuming both systems use the same syscall API (Windows NT, POSIX...).
For openCV you do this by setting the BUILD_SHARED_LIBS build flag to false (see OpenCV as a static library (cmake options), the following line is taken from there):
cmake -DBUILD_SHARED_LIBS=OFF ..
Once you have done this, you will see that the openCV folder looks very similar to the one you have now, except that in your 'lib' folder there will now be .lib-files instead of .dll files (at least if you are working on Windows, which I assume you do since you are using Visual Studio).
Next step is to go to your project settings and set your linker to link with the static libraries instead of the dynamically ones. If you have used openCV's local method for linking, you can go to project settings -> linker -> input -> Addtional dependencies. There you change the extension of all the openCV libraries from .dll to .lib.
Now you should be able to rebuild your application and the resulting exe-file should have all dependent libraries contained in it.

Compile libupnp on windows

I'm trying to compile libupnp-1.6.17 on windows with VS2008, but hundreds syntax errors occured. I download source code from http://sourceforge.net/projects/pupnp/
anyone tell me how to compile libupnp on windows?
WINDOWS BUILD
In order to build libupnp under Windows the pthreads-w32 package is required.
You can download a self-extracting ZIP file from the following location:
ftp://sources.redhat.com/pub/pthreads-win32/pthreads-w32-2-7-0-release.exe
or possibly newer versions if available.
Execute the self-extracting archive and copy the Pre-build.2 folder to the
top level source folder.
Rename Pre-build.2 to pthreads.
Open the provided workspace build\libupnp.dsw with Visual C++ 6.0 and select
Build->Build libupnp.dll (F7)
In the build directory there are also VC8, VC9 and VC10 folders containing
solution files for Visual Studio 2005/2008/2010 respectively.
If you use newer versions to build libupnp, eg Visual Studio 2003 or later,
then you need to rebuild the pthreads package so it uses the same VC runtime
as libupnp to prevent cross boundary runtime problems
(see http://msdn.microsoft.com/en-us/library/ms235460%28v=VS.100%29.aspx).
Just replace the files in the Pre-build.2 folder (renamed to pthreads as
mentioned above) with the newly build versions.
If you also use a newer version of pthreads-win32 then you should also
replace the header files in that directory structure (obviously).
For building a static library instead of a DLL and for using the static
pthreads-w32 library following switches need to be defined additionally:
UPNP_STATIC_LIB - for creating a statically linkable UPnP-library
PTW32_STATIC_LIB - for using the static pthreads32 library