程序适用于VS 2013,但不适用于.exe

时间:2013-11-18 07:50:50

标签: c++ directx visual-studio-2013

我使用Direct X 11在Visual Studio 2013中创建了一个测试程序。它由一个简单的精灵组成,它基于计时器实现缓慢旋转。程序使用F5或Ctrl-F5加载并运行正常,但是当我尝试打开实际创建的.exe(在我的\ Debug文件夹中)时,它只显示窗口然后立即关闭。

我在这个问题上阅读的大多数答案都对应于从visual studio中加载.exe。我也试过发布模式,但同样的事情发生了。

1 个答案:

答案 0 :(得分:6)

Sprite文件保存在项目文件夹中。 Visual Studio IDE中的默认运行位置是您正在执行的项目的项目文件夹。也就是说,通常它是从保存.vcproj或.vcprojx文件的目录执行的(通常是解决方案目录文件夹下面的一个文件夹,保存.sln文件)。

如果您的项目从IDE正确运行,但无法直接从调试文件夹运行,则很可能您依赖于项目文件夹中源项目旁边的项目数据文件。从Debug文件夹运行时,这些文件不再可见,因为Debug文件夹是您的工作目录;不是项目文件夹。

有许多方法可以解决这个问题,每个方法都有自己的优点。一些选项是:

制作后步骤

为您的项目制作一个后期构建步骤,将您的数据文件复制到项目的$(TargetDir)位置。然后,这些文件将显示在与可执行文件相同的目录中。

Benefit: Its easy.
Drawback: It will always run if you click "build solution" even if the data files are "up-to-date."

自定义构建目标

将数据文件添加到项目中并编写执行相同副本的自定义构建脚本,但也会建立输出依赖项文件。

Benefit: Almost as easy as #1, but a little more tedious.
Drawback: You may have a lot of data files and each will require its own custom build step. (Note: you can multi-select all the data files in your project, and if you're creative with the built-in macros you can have them all use the "same" build rules and commands).

嵌入资源

将数据文件作为自定义资源添加到可执行文件中。

Benefit: Your project no longer requires data files side-by-side with the executable since they are embedded in the resource table of your EXE module.
Drawback: Custom code is required to dynamically load the custom resources from your executable's resource table rather than off-disk. It isn't difficult at all to do, but is additional work.

还有其他选择,但我希望这会给你一些想法。

相关问题