单机 VS 2010 C++程序
我已经很久没有使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最简单的方法就是安装 VC++ Redistributable Package。它具有 x86 和x64 版本。
The easiest thing to do is to just install the VC++ Redistributable Package. It has both x86 and x64 versions.
首先,在我真正向您提供详细信息之前:
警告
如果您这样做,事情会因为两个原因而变得很糟糕:
一种可能的解决方案是使用
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:
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.
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.
打开项目的属性对话框,然后选择配置属性| 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.
之前的答案< /a> 应该适用于 VS2010。我仍然使用 VS2005 进行构建,但我所有的应用程序都使用静态 CRT,唯一的原因是能够在新旧机器上运行。
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.