程序可以在VS2013中运行,但不能在.exe中运行
Program works in VS 2013 but not the .exe
我在Visual Studio 2013中使用Direct X 11制作了一个测试程序。它由一个简单的精灵组成,它根据定时器实现缓慢旋转。该程序使用F5或Ctrl-F5加载并运行良好,但当我尝试打开实际创建的.exe(在我的\Debug文件夹中)时,它只显示窗口,然后立即关闭。
我读到的关于这个问题的大多数答案都对应于从visualstudio内部加载.exe。我也尝试过释放模式,但同样的事情也发生了。
Sprite文件保存在项目文件夹中。VisualStudioIDE的默认运行位置是您正在执行的项目的项目文件夹。也就是说,它通常从保存.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.
还有其他选择,但我希望这能给你一些想法。
相关文章:
- 是否可以将函数导入命名空间,但不能导出它?
- Eclipse 中的 Makefile 项目可以运行,但不能调试,为什么?
- SImple 代码在 DevC++ 中正确运行,但不能在 Visual Studio Code 中正常运行
- C++程序在Linux上完美运行,但不能在Windows上运行
- QT创建者简单的C 程序来自IDE,但不能从Command LNE运行
- 在我的CUDA运行时间计划中,CPU和GPU可以异步计算,但不能合作地计算
- 网络应用程序可以在模拟器中运行,但不能在iPhone上运行
- 程序可以在VS2013中运行,但不能在.exe中运行
- 我的C++ Unity 插件在编辑器中运行一次,但不能运行两次
- 可以从命令行运行C++代码,但不能从visual studio中的调试模式运行
- Netbeans Cpp编译和运行项目,但不能使用cppunit进行测试
- 当使用CreateProcessLogonW或类似的方法启动时,进程启动,但不能运行
- Qt应用程序可以在台式机上运行,但不能在笔记本电脑上运行
- Visual Studio 2010 c++ SDL游戏可以在它编译的计算机上运行,但不能在任何其他计算机上运行
- Qt GUI应用程序可以在我的电脑上运行,但不能在其他电脑上运行
- 编译后的python库可以在一台计算机上运行,但不能在另一台计算机上运行
- 程序可以在视频上运行,但不能在本地运行(可能是内存错误)
- 一切都是正确的,但不能运行:错误预期{或;
- SDL程序可以自己运行,但不能通过命令行运行
- Eclipse可以编译,但不能运行