Creating an executable application with static libraries (OpenCV, DLib) on Visual Studio

asked 2018-11-05 09:40:22 -0500

ameypar94 gravatar image

I am using Windows 10, Visual Studio 2017, Opencv 3.4.3 and Dlib 19.16. I am creating an annotation tool for labeling certain data, everything seems to work fine. My only concern is I am not able to create an executable (.exe) file for this application which is built on static libraries and is self sufficient. Any help with this? Thanks!

edit retag flag offensive close merge delete


everything seems to work fine.

well, obviously, not so ;)

I am not able to create an executable

well, tell us why it is so ! we need to see, what you try to link, how so (order matters !) and the errors you get

berak gravatar imageberak ( 2018-11-05 09:43:55 -0500 )edit

"everything seems to work fine" by this I mean there are no errors in running code. Only issue is the libraries are dynamically linked, so whenever I try to use .exe file of the project outside Visual Studio environment, It throws errors like "Unable to open shape_predictor_68_face_landmarks.dat for reading."(From dlib face detector) or "The code execution cannot proceed because opencv_world343.dll was not found. Reinstalling program may fix the problem.". Sorry if the question was unclear. This is my first time posting question here, so forgive my errors!

ameypar94 gravatar imageameypar94 ( 2018-11-05 09:52:49 -0500 )edit

You can't.

supra56 gravatar imagesupra56 ( 2018-11-05 09:53:31 -0500 )edit

@ameyparanjape -- that's not a linking, but a runtime problem. the path to dlib's dat file is either wrong, or the file is broken.

Sorry if the question was unclear.

main problem now ;)

please update your question (maybe clean it up a bit), show the code, that tries to load it, and the directory structure (you can use the tree program :)

berak gravatar imageberak ( 2018-11-05 10:00:42 -0500 )edit

@berak I had no issues running the same routine when I did it inside the Visual Studio project (i.e. when I run .sln file), it was built successfully, and I could even use it to annotate images. So definitely the path to dlib .dat file is not wrong. I will update my question. The errors only show up when I try to run .exe file outside the Visual Studio environment or on any other Windows system which does not have opencv and/or dlib. Thanks!

ameypar94 gravatar imageameypar94 ( 2018-11-05 10:08:27 -0500 )edit

ok, "wrong" is probably the "wrong" word here ;)

and indeed, relative path will differ, when run from an ide or not. most noobs get bitten by that ;)

berak gravatar imageberak ( 2018-11-05 10:10:28 -0500 )edit

So, I would like to know, if this is even possible at the first place that, I have a Visual Studio C++ project that uses OpenCV and Dlib. I want to make it into an application(.exe), which can be executed on any Windows system regardless it has Visual Studio, Dlib, OpenCV installed on it. @supra56 said straight NO

ameypar94 gravatar imageameypar94 ( 2018-11-05 10:14:34 -0500 )edit

The code execution cannot proceed because opencv_world343.dll

this means, you did NOT use static linking correctly !

@supra56 said straight NO

even IF you link it statically, all it means, it no more depends on further opencv dll's. there are still windows system libs, the vc runtime, it was compiled against etc. it's far easier, if your program was built on an older windows vversion, and you try to run it on a newer one, than the other way round

berak gravatar imageberak ( 2018-11-05 10:25:32 -0500 )edit

@ameyparanjape. I don't know if this could help exe

supra56 gravatar imagesupra56 ( 2018-11-05 10:54:32 -0500 )edit

@ameyparanjape I think you can download this wxOpencv20171203. It's an opencv application in static : no dll except opencv_ffmpeg

If it works then you can try to build opencv in static using

LBerger gravatar imageLBerger ( 2018-11-05 11:51:00 -0500 )edit