How to include all dll's in exe?

前端 未结 4 636
不知归路
不知归路 2021-02-14 16:04

I have a Visual Studio 12 project; source code written in C++; it\'s an OpenCV project. I want to give my compiled program to someone else, but, on other PC, I getting an error

相关标签:
4条回答
  • 2021-02-14 16:41

    You can use the Windows Dependency Walker to determine which DLLs your program needs to run.

    Actually, this only tells you which DLLs your program needs to launch successfully. If you load DLLs dynamically (via LoadLibrary) then you are on your own.

    0 讨论(0)
  • 2021-02-14 16:42

    If you opt for the accepted solution (package the DLLs with the EXE file), and you don't want to go into the trouble of finding which DLLs to use, then you can copy all the OpenCV DLLs. They're not so big (65 MB on OpenCV 2.43). They are located at ...\opencvXXX\build\x64\vc10\bin\

    where XXX is the OpenCV version. You can use x64 or x86 depending on your platform (32 or 64-bit). And the version of vc can be different on your system (vc9, vc10, etc...)

    0 讨论(0)
  • 2021-02-14 16:48

    the more complicated solution would be, to build static opencv libraries from src, then link your program against those, resulting in 1 large binary exe-chunk, that does not use any dlls (apart from ffmpeg, not sure about that one).

    to build static libs, you'd need to run cmake with : BUILD_SHARED_LIBS=OFF

    but take a deep breath, before doing that. linking your program will be sigificantly more difficult, because now you have to link all the zlib,libpng, whatever dependecies manually ( which before got conveniently linked into your dlls )

    again, the most simple solution is to deploy all the opencv dlls with your program.

    0 讨论(0)
  • 2021-02-14 16:55

    DLLs themself can not be "statically linked" into an executable; that completely defies their purpose (well, actually you can use some really weird voodoo tricks to actually do it, but this is neither recommendable nor should you try it if you have to ask this question).

    The simple solution would be to identify all the DLLs your program requires (just starting the program in the Debugger will generate a log file listing them all) and copy those DLLs into the same directory as the EXE resides in; as it happens the directory with the EXE file in is also the first directory where the system looks for DLLs before advancing to the standard system directories in default configuration. Package it up and distribute it that way.

    0 讨论(0)
提交回复
热议问题