38

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

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

4

6 回答 6

18
  1. 选择项目 -> 属性
  2. 选择配置 -> 常规
  3. 在应如何链接 MFC 的框中,选择静态链接它。
  4. 选择链接器 -> 输入。在Additional Dependencies下,添加您需要应用静态链接的任何库。
于 2008-08-13T18:10:34.870 回答
10

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

  • 多线程调试/发布
  • 单线程调试/发布

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

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

于 2008-08-07T21:11:52.817 回答
4

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.

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.

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.

于 2008-09-09T11:41:09.910 回答
0

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

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

于 2008-08-06T12:10:55.920 回答
0

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

于 2008-08-07T06:40:28.177 回答
0

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

于 2020-03-05T19:29:23.967 回答