c++ - 无法在任何其他机器上运行 Windows 应用程序

标签 c++ windows

<分区>

我最近为 windows 应用程序编写了一个相当简单的代码,一个 2048 游戏,包括一些基础知识,例如图标、背景和东西,4 个不同方向的按钮和 4x4 阵列的静态窗口输出。该代码并不是真的“好”,但由于我仍在学习,我发现它已经足够了,因为它可以工作(至少在我的 PC 上)。我使用的是默认的 VS13 配置,安装后没有做任何更改,代码是用 C++ 编写的。 代码可以在这里找到:https://www.dropbox.com/sh/15y1daq2h3jm8p7/AADp0m1EfUJo3W2z315Zgd0Wa

现在让我感到困扰的是,当我通过调试或从 PC 上的桌面运行程序时,该程序编译时出现 0 个警告或错误,并且按照我的预期运行,但是当我将其上传到 Dropbox 并想要启动时,让我们开始吧在笔记本电脑上说它不起作用。 此外,如果我尝试在 Codeblocks 中编译完全相同的代码,我也做不到,并且会出现许多函数未在范围内声明的警告。 任何人都可以解释为什么会发生这种情况,我该如何解决?

最佳答案

您面临的基本问题是,您正试图在 Visual Studio 环境之外为您编写的 VCPP 代码编译代码。

当您使用 Visual Studio 调试代码时,所有必需的文件/依赖项都会在编译期间注入(inject)。

我建议使用 Visual Studio 打包代码并尝试在笔记本电脑上运行 exe。

确保您在目标机器上安装了正确版本的 VC++ 运行时环境。 (您还可以选择将设置包含在打包的设置中。)


来自这里:https://stackoverflow.com/a/20890610/1477051

As you can see here, the MSVCP DLL is the platform's implementation of the C++ Standard Library. In short what that means is you cannot distribute your application without needing the "stuff" that these libraries provide. All compilers regardless of platform would need some kind of implementation of the Standard Library. Typically this is distributed in the form of libraries.

However you can distribute your application so that the "stuff" is built in to your program directly, rather than being shipped in a separate DLL. In order to do this, you must statically link your application to the Standard Library.

There are a few ways to accomplish this. One way is in Project Settings. In "Configuration Properties" > "C/C++ Code Generation" > "Runtime Library", choose "Multithreaded (/MT)" as opposed to "Mutithreaded (Static)".

By the way, the "D" in "MSVCP120D.dll" you mentioned above means "Debug." This means that you are trying to distribute a debug build of your program. You should (almost) never do this. Distribute release builds instead.

关于c++ - 无法在任何其他机器上运行 Windows 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23534372/

相关文章:

c++ - 在我自己的类中捕获并处理所有异常

Windows 批处理文件 : how to compare command line argument to an integer

c++ 问题,关于 * 和 ->

c++ - 如何将元素移动到 vector 的末尾?

c++ - LibXML 不返回 xpath 结果

windows - Powershell 警告和错误处理

c# - 打开自定义文件,args 始终为空

类中的 C++ std::vector,函数在返回值和大小在 foreach 中增长时崩溃

c# - 尝试访问 USB 设备时的 RPC_E_CANTCALLOUT_ININPUTSYNCCALL

linux - 如何让Windows上的Apache Spark访问Linux上的Hadoop?