C++打包EXE程序同时打包DLL文件-直接让其在其他电脑完美运行

通过清心醉

C++打包EXE程序同时打包DLL文件-直接让其在其他电脑完美运行

打开Visual Studio ,选择工具,选择命令行,选择开发者PowerShell
比如我当前的应用叫辅助程序
PS D:\VisualStudioProjects\辅助程序> cd x64
PS D:\VisualStudioProjects\辅助程序\x64> cd release
进入release目录

注意:VS编译的时候,记得要选择X64


PS D:\VisualStudioProjects\辅助程序\x64\release> dumpbin /dependents 辅助程序.exe
Microsoft (R) COFF/PE Dumper Version 14.37.32822.0
Copyright (C) Microsoft Corporation. All rights reserved.

Dump of file 辅助程序.exe

File Type: EXECUTABLE IMAGE

Image has the following dependencies:

mfc140u.dll
KERNEL32.dll
USER32.dll
GDI32.dll
SHELL32.dll
COMCTL32.dll
SHLWAPI.dll
gdiplus.dll
MSVCP140.dll
VCRUNTIME140_1.dll
VCRUNTIME140.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll

Summary

    1000 .data
    1000 .pdata
    8000 .rdata
    1000 .reloc
   14000 .rsrc
   14000 .text

PS D:\VisualStudioProjects\辅助程序\x64\release>

这样我们就能看到我们需要的DLL文件以下:

mfc140u.dll
KERNEL32.dll
USER32.dll
GDI32.dll
SHELL32.dll
COMCTL32.dll
SHLWAPI.dll
gdiplus.dll
MSVCP140.dll
VCRUNTIME140_1.dll
VCRUNTIME140.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
api-ms-win-crt-stdio-l1-1-0.dll
api-ms-win-crt-filesystem-l1-1-0.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-locale-l1-1-0.dll

这几个文件就是我们需要的(一般在C:\Windows\System32目录,如果找不到自己C盘整个搜索)
自己C盘创建一个文件夹,比如我创建一个c:\qingxinzui文件夹
把辅助程序.exe复制进去,还有把上面的所有dll复制进去就可以了。
注意,比如说MFC应用里有自己创建的config.ini这种配置文件
(程序里打开需要在默认目录,即和.cpp .h文件同一个目录里的自己创建的文件)
也需要一起复制到qingxinzui目录,这样就可以了。

这时候我们只需要将qingxinzui直接压缩,然后其他电脑上就可以直接完美运行。

关于作者

清心醉 administrator

发表评论

请输入验证码: