我目前正在使用 C++ 开发游戏引擎。随着项目的进一步推进,我注意到生成的可执行文件通常不会反射(reflect)最新的代码更改。但是完全清理解决方案并重建它可以解决问题。不幸的是,对于更大的代码库,完全重建不再是可行的选择。
我已经在 stackoverflow 上检查了不同的解决方案:
- 我检查过我的“Build and Run”设置是否设置为“Always build ”
- Configuration Manager 也设置为“Build”
附加信息:
- 这是一个
OpenGL
项目,带有GLFW
和glad
在 c++ 中 - 我使用 Visual Studio Community 2017 版本 15.2
这是一个非常烦人的问题,会导致大量生产力损失,因为每次我想看到更改时,我都必须完全重建整个解决方案。如果有任何意见,我将不胜感激。请询问是否需要更多信息。
我不知道这是否有任何相关性,但这是我对 TestScene.cpp 进行小改动并重新运行代码时得到的结果:
更新
下面是对这个问题的深入解释:
- 我有一个允许旋转对象的类 TransformerScript.cpp
- 我已将旋转速度设置为 1。
- 对象按预期旋转。
- 现在我将速度浮点值从 1 更改为 0。
- 我按下运行(本地 Windows 调试器)
- 这是输出日志:
1>------ Build started: Project: Star-Engine, Configuration: Debug x64 ------
1>TransformerScript.cpp
1>c:\users\haeri\documents\github\space-engine\star-engine\src\header\matrix4f.h(44): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
1>c:\users\haeri\documents\github\space-engine\star-engine\src\header\matrix4f.h(44): warning C4244: 'initializing': conversion from 'float' to 'int', possible loss of data
1>c:\users\haeri\documents\github\space-engine\star-engine\src\header\matrix4f.h(45): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
1>c:\users\haeri\documents\github\space-engine\star-engine\src\source\transformerscript.cpp(13): warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data
1>Compiling...
1>Generating Code...
1>Skipping... (no relevant changes detected)
1>TestScene.cpp
1>Star-Engine.vcxproj -> C:\Users\haeri\Documents\github\Space-Engine\x64\Debug\Star-Engine.exe
c:\users\haeri\documents\github\space-engine\star-engine\src\source\glad.c(51): warning C6308: 'realloc' might return null pointer: assigning null pointer to 'exts_i', which is passed as an argument to 'realloc', will cause the original memory block to be leaked.
c:\users\haeri\documents\github\space-engine\star-engine\include\stb\stb_image.h(3667): warning C6001: Using uninitialized memory 'coutput'.
1>Star-Engine.vcxproj -> C:\Users\haeri\Documents\github\Space-Engine\x64\Debug\Star-Engine.pdb (Partial PDB)
1>Done building project "Star-Engine.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
- 编译后的可执行文件开始
- 结果是同一个图形以相同的速度旋转。
- 预期行为:没有旋转,因为 float 设置为 0。
- 我被迫“清理解决方案”和“重建解决方案”
- 这在我的笔记本电脑上大约需要 1 到 2 分钟
- VS 完成重建新解决方案
- 我按下运行(本地 Windows 调试器)
- 物体没有移动。 (这是预期的)
替代方法
- 在速度浮点值的位置设置断点
- 我按下运行(本地 Windows 调试器)
- 有时(90% 的情况)会弹出错误提示。其他时候(10% 的情况)一切都按预期进行
- 我按确定
- 编译后的可执行文件开始
- 结果是同一个图形以相同的速度旋转。
- 预期行为:没有旋转,因为 float 设置为 0。
- 断点未触发!
最佳答案
我的一个 C# 项目遇到了同样的问题,并且这样解决了:
- 转到解决方案 > 属性
- 检查配置属性 > 配置
- 在我的例子中,没有为解决方案中的一个项目检查构建标志
关于c++ - Visual Studio 需要为每次更改重建解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45688562/