单机 VS 2010 C++程序

发布于 2024-10-17 09:37:15 字数 614 浏览 2 评论 0原文

我已经很久没有使用 VS 2010 和 C++ 了,当我重新开始使用它时,我遇到了去年困扰我的同样的问题:我编译的 exe 不能很好地运行没有正确的 C++ 运行时的旧机器。我什至不知道给他们什么链接,我告诉他们安装 后出现错误,提示“由于计算机中缺少 MSVCR100.dll,因此程序无法启动。请尝试重新安装该程序以解决此问题。单击“确定”关闭应用程序。”)。所以我进去并将代码生成设置为 /MT 并禁用了相当多的选项,并尝试使用很多选项,但结果仍然相同。

我的问题是:是否有完整的 VS 2010 C++ 发行版列表,我可以提供并告诉他们安装,这样我在 VS 2010 上编译的所有 C++ 程序都可以在 Windows XP 上运行,甚至更好,这是一种通用的方法一个独立的 exe,包含其工作所需的所有内容,并且不依赖 DLL?我想链接到一个包含 exe 引用的所有内容的库。如果有帮助的话,我正在为 x64 和 x86 构建。

PS清单文件怎么了,我应该包含它还是不包含它?

it's been a long while since I've used VS 2010 and C++, and as I'm getting back to using it, I'm running into the same problems that plagued me last year: the exe's that I compile do not run well on older machines that do not have the correct C++ runtimes. I do not even know what link to give them, and I told them to install this after they had an error that said "The program can't start because MSVCR100.dll is missing from your computer. Try Reinstalling the program to fix this problem. Click OK to close the application."). So I went in and set the code generation to /MT and disabled quite a few options, and tried messing around with lots of options, but still the same result.

My question is: Is there a list of complete VS 2010 C++ distributables that I can just give and tell them to install so all of the C++ programs I compile on my VS 2010 will work on Windows XP, or even better, a way to general a standalone exe that contains all it needs to work, and does not rely on DLLs? I'm thinking like linking to a library that has everything the exe references. If it helps, I'm building for both x64 and x86.

P.S. What's up with the manifest file, should I include it or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

面如桃花 2024-10-24 09:37:15

最简单的方法就是安装 VC++ Redistributable Package。它具有 x86x64 版本。

The easiest thing to do is to just install the VC++ Redistributable Package. It has both x86 and x64 versions.

椵侞 2024-10-24 09:37:15

首先,在我真正向您提供详细信息之前:


警告

如果您这样做,事情会因为两个原因而变得很糟糕:

  1. 如果 MSVC 运行时中存在安全性或其他错误,并且您采用这种方法,它们会被烘焙到您的应用程序中意味着您需要重新分发。 DLL 是首选,因为理论上人们使用系统更新,这意味着任何错误都会得到修复。
  2. 编译到 exe 中的其他所有内容也需要执行此操作。如果不这样做,您最终会得到两个版本的代码,并且您使用的任何内容都不会链接。

一种可能的解决方案是使用 cl.exe 选项(C/C++ 编译器设置)/MT 将 MSVC 运行时烘焙到您的应用程序中,这意味着多线程版本的C/C++ 运行时静态链接。正如我所说,如果您尝试链接到动态链接到运行时的某些内容,您最终会陷入混乱。另外,正如我所说,这代表了一个额外的安全风险因素,因此请记住这一点。

其他选项是编写一个安装程序,可以下载适当的运行时,或包含所需的 DLL。

如果您使用的运行时的某些功能超出了特定 Windows 版本(通用声明,但确实发生了),那么您应该能够使用 Windows SDK 来使用适当的 C 运行时来定位各种版本的 Windows。

Firstly, before I actually give you the detail:


Warning

If you do this, things will be bad for two reasons:

  1. If there are security or other bugs in the MSVC runtimes, and you take this approach, they're baked into your app which means you need to re-distribute. DLLs are preferred because theoretically people use system update which means any errors get fixed.
  2. Everything else you compile into your exe also needs to do this. If you don't, you end up with two versions of the code and whatever you're using won't link.

One possible solution is to bake the MSVC runtime into your application, by using the cl.exe option (C/C++ compiler settings) /MT which means multi-threaded version of the C/C++ runtime linked statically. As I said, if you try to link against something that is linked itself dynamically to the runtime, you're going to end up in a mess. Also, as I said, this represents an additional security risk factor, so bear that in mind.

The other options are to write an installer that can either download the appropriate runtime, or include the DLL needed.

If you're using some feature of the runtime that exceeds a certain version of Windows (generic statement, but it does happen) then you should be able to use the Windows SDK to target various versions of Windows using appropriate C runtimes.

清风挽心 2024-10-24 09:37:15

http://www.microsoft.com /downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84

google text: Visual Studio c++ redist

不要静态链接到运行时;如果您将任何类型的 dll 用于其他目的,请特别不要这样做。它引入了有关堆管理的各种虚假问题,您可能不想搞乱这些问题。

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=a7b7a05e-6de6-4d3a-a423-37bf0912db84

google text: visual studio c++ redist

Do not statically link to the runtime; specifically don't do so if you're using any kind of dll for other purposes. It introduces all kinds of bogus problems wrt heap management that you probably don't want to mess with.

眼藏柔 2024-10-24 09:37:15

打开项目的属性对话框,然后选择配置属性| C/C++ |代码生成。默认设置是多线程 DLL。将其更改为多线程,您将构建 .EXE 并静态链接运行时。不要忘记对调试版本执行相同的操作。

如果您使用的是 MFC 或 ATL,则需要导航到“配置属性”|“配置属性”。常规并设置“使用MFC”或“使用ATL”以静态链接。

注意:如果静态链接运行时,则必须确保您链接的任何其他库也静态链接它。否则,您最终会在内存中得到运行时的两个副本,每个副本都有自己的堆,并且当使用一个运行时的代码尝试释放另一个运行时分配的对象时,就会发生不好的事情。

Open the properties dialog for your project and select Configuration Properties | C/C++ | Code Generation. The default setting is Multi-threaded DLL. Change that to Multi-threaded and you'll be building and .EXE with the run-time statically linked in. Don't forget to do the same for the debug version.

If you're using MFC or ATL, you will need to navigate to Configuration Properties | General and set "Use of MFC" or "Use of ATL" to link statically as well.

NB: If you link the runtime statically, you must make sure that any other library you're linking in also links it in statically. Otherwise you'll wind up with two copies of the runtime in memory, each with its own heap and bad things will happen when code using one runtime tries to free an object allocated by the other runtime.

2024-10-24 09:37:15

This previous answer should hold true for VS2010. I still build with VS2005, but all my apps use the static CRT for the sole reason of being able to run across old and newer machines alike.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文