您如何打包要发布的 Visual Studio C++ 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:11:11  来源:igfitidea点击:

How do you pack a visual studio c++ project for release?

c++visual-studio

提问by DShook

I'm wondering how to make a release build that includes all necessary dll files into the .exe so the program can be run on a non-development machine without it having to install the microsoft redistributable on the target machine.

我想知道如何制作一个包含所有必要 dll 文件到 .exe 的发布版本,以便程序可以在非开发机器上运行,而无需在目标机器上安装 microsoft 可再发行组件。

Without doing this you get the error message that the application configuration is not correct and to reinstall.

如果不这样做,您会收到错误消息,指出应用程序配置不正确并需要重新安装。

采纳答案by Michael Pryor

  1. Choose Project -> Properties
  2. Select Configuration -> General
  3. In the box for how you should link MFC, choose to statically link it.
  4. Choose Linker -> Input. Under Additional Dependencies, add any libraries you need your app to statically link in.
  1. 选择项目 -> 属性
  2. 选择配置 -> 常规
  3. 在应如何链接 MFC 的框中,选择静态链接它。
  4. 选择链接器 -> 输入。在Additional Dependencies 下,添加您需要应用静态链接的任何库。

回答by Michael Pryor

You need to set the run-time library (Under C/C++ -> Code Generation) for ALL projects to static linkage, which correlates to the following default building configurations:

您需要将所有项目的运行时库(在 C/C++ -> 代码生成下)设置为静态链接,这与以下默认构建配置相关:

  • Multithreaded Debug/Release
  • Singlethreaded Debug/Release
  • 多线程调试/发布
  • 单线程调试/发布

As opposed to the "DLL" versions of those libraries.

与这些库的“DLL”版本相反。

Even if you do that, depending on the libraries you're using, you might have to install a Merge Module/framework/etc. It depends on whether static LIB versions of your dependencies are available.

即使你这样做,根据你使用的库,你可能必须安装一个合并模块/框架/等。这取决于您的依赖项的静态 LIB 版本是否可用。

回答by Simon Steele

Be aware that Microsoft do not recommend that you static link the runtime into your project, as this prevents it from being serviced by windows update to fix critical security bugs. There are also potential problems if you are passing memory between your main .exe and .dll files as if each of these static links the runtime you can end up with malloc/free mismatch problems.

请注意,Microsoft 不建议您将运行时静态链接到您的项目中,因为这会阻止 Windows 更新为其提供服务以修复关键的安全错误。如果您在主 .exe 和 .dll 文件之间传递内存,也存在潜在问题,就好像这些静态链接运行时一样,您最终可能会遇到 malloc/free 不匹配问题。

You can include the DLLs with the executable, without compiling them into the .exe and without running the redist tool - this is what I do and it seems to work fine.

您可以在可执行文件中包含 DLL,而无需将它们编译到 .exe 中,也无需运行 redist 工具 - 这就是我所做的,它似乎工作正常。

The only fly in the ointment is that you need to include the files twice if you're distributing for a wide range of Windows versions - newer OSs need the files in manifest-defined directories, and older ones want all the files in the program directory.

唯一美中不足的是,如果您要为范围广泛的 Windows 版本分发文件,则需要将文件包含两次 - 较新的操作系统需要清单定义目录中的文件,而较旧的操作系统需要程序目录中的所有文件.

回答by RedBruhMoment

You should use a static link and add all libraries you need under additional dependencies.

您应该使用静态链接并在附加依赖项下添加您需要的所有库。

回答by Josh

You'd be looking to static link (as opposed to dynamically link)

你会寻找静态链接(而不是动态链接)

I'm not sure how many of the MS redistributables statically link in.

我不确定有多少 MS 可再发行组件静态链接。

回答by David Sykes

If you are looking to find out which dll's your target machine is missing then use depends.exe which used to come with MSDev, but can also be found here. Testing this on a few target machines should tell you which dll's you need to package with your application.

如果您想找出您的目标机器缺少哪个 dll,请使用 MSDev 附带的depends.exe,但也可以在此处找到。在几台目标机器上进行测试应该会告诉您需要将哪些 dll 打包到您的应用程序中。