简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM