简体   繁体   English

Visual C ++生成/调试问题

[英]Visual C++ Build / Debugging Issue

I'm having a weird problem with Visual Studio. 我在Visual Studio中遇到一个奇怪的问题。 Whenever I change my code and build, even though I get the notification that the built was successful (and if any, it also shows errors in code and doesn't build) the executable is actually the previous build. 每当我更改代码并构建时,即使我收到构建成功的通知(如果有的话,它也会显示代码错误并且没有构建),该可执行文件实际上就是先前的构建。 This is getting really annoying and frustrating. 这真令人烦恼和沮丧。

If I put a breakpoint on the new lines, the breakpoint gets disabled and it says 如果我在新行上放置一个断点,该断点将被禁用,并显示

The breakpoint will not currently be hit. 断点当前不会被命中。 No executable code is associated with this line. 没有可执行代码与此行相关联。 Possible causes include: preprocessor directive or compiler/linker optimization 可能的原因包括:预处理程序指令或编译器/链接器优化

If I put a breakpoint on old lines of code, it stops processing but shows me this message 如果在旧代码行上设置断点,它将停止处理,但会显示此消息

The source is different from when the module was built. 来源与构建模块时的来源不同。 Would you like the debugger to use it anyway? 您是否仍要调试器使用它?

I never had this problem before and the source code in on my laptop's hard drive. 我以前从未遇到过此问题,源代码已存储在笔记本电脑的硬盘上。 It saves right away. 立即保存。 The only way to get around this to Clean the entire solution manually every time, instead of basically pressing F5. 解决此问题的唯一方法是每次手动Clean整个解决方案,而不是基本上按F5键。

Thanks everyone for their suggestions. 感谢大家的建议。 My mistake was that I defined the classes inside .cpp files, this somehow caused the linker to do weird (caching probably) stuff and link the old objects. 我的错误是我在.cpp文件中定义了类,这以某种方式导致链接器执行奇怪的操作(可能是缓存)并链接了旧对象。 I renamed the file to .h and everything's working as expected. 我将文件重命名为.h并且一切正常。

I faced the same problem. 我遇到了同样的问题。 But reason was not as yours. 但是理性却不是你的。 Then I just restarted the visual studio and it ran as expected. 然后,我刚刚重新启动了Visual Studio,它按预期运行。

Perhaps your code is not built, or is built in a way you don't expect. 也许您的代码未构建,或者以您不期望的方式构建。

You might check by inserting a #error foobar preprocessor directive somewhere. 您可以通过在某处插入#error foobar预处理程序指令进行检查。 If no error shows when building, you know you are in trouble! 如果在构建时未显示任何错误,则说明您遇到了麻烦!

But I never used Visual Studio (I'm only using Linux) so I cannot help more. 但是我从未使用过Visual Studio(我仅使用Linux),所以我无能为力。

I think you are using source files from another project (ex: if you are using a dll say, my.dll (which was built using some source files say, mycpp.cpp ); in your current project). 我认为您正在使用另一个项目中的源文件(例如:如果您使用的是dll,则为my.dll(使用当前项目中的某些源文件(如mycpp.cpp)构建); When you debugged into the file (mycpp.cpp), maybe you modified it. 当您调试到文件(mycpp.cpp)时,也许您已对其进行了修改。

Hence you need to rebuild the dll (my.dll) first in the project in which you created my.dll . 因此,您需要首先在创建my.dll的项目中重建dll(my.dll)。 Or Maybe you have opened a instance of mycpp.cpp in a window & debugging in another window. 或者,也许您已经在一个窗口中打开了mycpp.cpp的实例,并在另一个窗口中进行了调试。 you should rebuild the dll. 您应该重建dll。

If you are not using files from another project, then I cant guess the cause...but still I would recommend using rebuild rather than clean & build . 如果您没有使用其他项目中的文件,那么我无法猜测原因...但是我仍然建议您使用rebuild而不是cleanbuild

please clarify your Question a bit. 请澄清您的问题。 @David expecting a reply from you... @David期待您的回复...

It might be that you have set main project some other project and building that. 可能您已将主项目设置为其他项目并进行了构建。 make your project that you want to work on as "Main Project " by set main project available in menu bar. 通过设置菜单栏中的可用主项目,使要处理的项目成为“主项目”。

I was looking for an answer to this issue since I was also stuck with it. 我一直在寻找这个问题的答案,因为我也一直坚持下去。 A colleague of mine just gave me a solution that works. 我的一个同事给了我一个可行的解决方案。 Yes, it seems really stupid, but it did the trick for me. 是的,这看起来确实很愚蠢,但是它为我带来了成功。

Our solution has many projects. 我们的解决方案有很多项目。 He told me to select the project that I wish to break into and set it as the startup project (right-click on the project name and pick "Set as startup project"). 他告诉我选择我想进入的项目并将其设置为启动项目(右键单击项目名称,然后选择“设置为启动项目”)。 I was desperate, so I tried. 我很拼命,所以我尝试了。 To my amazement, it works. 令我惊讶的是,它有效。

Since I have this window opened, I thought I'd share it in case someone else is stuck with the problem. 由于我已打开此窗口,因此我想与他人共享,以防其他人陷入该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM