C++ 无法找到调试信息或与 Visual Studio 的不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2322876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:02:11  来源:igfitidea点击:

debugging information cannot be found or does not match visual studio's

c++cvisual-studiovisual-studio-2008

提问by numerical25

I copied an existing project and renamed the folder. Now I get this error when I try to compile the application

我复制了一个现有项目并重命名了该文件夹。现在,当我尝试编译应用程序时出现此错误

debugging information cannot be found or does not match. No symbols loaded.
Do you want to continue debugging ?

调试信息找不到或不匹配。没有加载符号。
要继续调试吗?

If I click yes, it compiles and runs fine. But now I have to deal with that message. Just curious about what I change in the projects properties to get it to stop.

如果我单击是,它会编译并运行良好。但现在我必须处理那个消息。只是好奇我在项目属性中更改了什么以使其停止。

采纳答案by Brian R. Bondy

The main reason is that you don't have a matching pdb and exe.

主要原因是你没有匹配的pdb和exe。

Some possible solutions:

一些可能的解决方案:

  • You are compiling in release instead of debug
  • You need to clean/build or rebuild
  • You don't have your pdb files being generated in the same directory as the exe
  • You have a mismatching pdb, maybe the copied source is newer than today's date and something isn't building properly.
  • Try cleaning out all debug object files
  • You are attaching to a process that you started from a different location from where your build exe and pdb exist
  • Restart Visual Studio
  • 您正在发布而不是调试中编译
  • 您需要清理/构建或重建
  • 您没有在与 exe 相同的目录中生成 pdb 文件
  • 您的 pdb 不匹配,可能复制的源比今天的日期新,并且某些内容构建不正确。
  • 尝试清除所有调试目标文件
  • 您正在附加到从与构建 exe 和 pdb 所在位置不同的位置启动的进程
  • 重新启动 Visual Studio

回答by Nicolas Guillaume

You probably have deactivated the debugging information for your project:

您可能已停用项目的调试信息:

  • Right click on your project -> Properties
  • Configuration properties -> Linker -> Debugging
  • Switch "Generate Debug Info" from No to Yes
  • 右键单击您的项目-> 属性
  • 配置属性 -> 链接器 -> 调试
  • 将“生成调试信息”从否切换为是

Rebuild your project and retry, it should now run without the message :)

重建您的项目并重试,它现在应该在没有消息的情况下运行:)

回答by Miguel

This happens to me every now and then, while debugging code and making changes it seems like visual studio caches the pdb information and sometimes it gets stuck. Doing a Rebuild solution, deleting the pdb and creating a new one doesn't fix the problem.

这种情况时不时地发生在我身上,在调试代码和进行更改时,visual studio 似乎缓存了 pdb 信息,有时它会卡住。执行重建解决方案,删除 pdb 并创建一个新的 pdb 并不能解决问题。

Of course I do have the generate debug information on and all that it's needed, specially since this happens while debugging the code several times.

当然,我确实有生成调试信息以及所有需要的信息,特别是因为在多次调试代码时会发生这种情况。

Visual Studio seems to be happy with the in-memory pdb and refuses to update it, regardless of time-stamps or even size changes in the pdb.

Visual Studio 似乎对内存中的 pdb 感到满意,并拒绝更新它,无论 pdb 中的时间戳甚至大小如何变化。

The only way to reset this is to exit Visual Studio (the IDE) and restart it again.

重置它的唯一方法是退出 Visual Studio(IDE)并重新启动它。

In some rare occurrences, the IDE might be still running in the background (process explorer shows it there) and might hold the handle to the file open. You can kill the process before restarting the IDE.

在极少数情况下,IDE 可能仍在后台运行(进程资源管理器在那里显示它)并且可能保持文件句柄处于打开状态。您可以在重新启动 IDE 之前终止该进程。

Good Luck

祝你好运

回答by AnT

I just encountered this error in VS2012. It is definitely caused by a bug in Visual Studio, which reveals itself in situations when the local PDB file of the main project has the same name as the final PDB file for the entire executable (even if the two are located in different directories!)

我刚刚在 VS2012 中遇到了这个错误。这肯定是由 Visual Studio 中的一个错误引起的,当主项目的本地 PDB 文件与整个可执行文件的最终 PDB 文件同名(即使两者位于不同的目录中!)

Consider this example.

考虑这个例子。

Solution consists of three projects: main, a, and b. mainis the top-level project for the executable, while aand bare libraries linked into main.

解决方案包括三个项目:maina,和bmain是可执行文件的顶级项目,而ab是链接到main.

In all three projects $(IntDir)variable is set to $(SolutionDir)\$(Configuration)\$(ProjectName)\. This means that project maindumps its intermediate files to Debug\main\, project a- to Debug\a\and so on.

在所有三个项目中,$(IntDir)变量都设置为$(SolutionDir)\$(Configuration)\$(ProjectName)\. 这意味着 projectmain将其中间文件转储到Debug\main\、project a-toDebug\a\等等。

In C/C++ -> Output Filessettings all three projects have Program Database File Namevalue set to $(IntDir)$(TargetName).pdb. This means that project maingenerates its local PDB file as Debug\main\main.pdb, project bas Debug\b\b.pdband so on.

C/C++ -> Output Files设置中,所有三个项目的Program Database File Name值都设置为$(IntDir)$(TargetName).pdb。这意味着 projectmain生成其本地 PDB 文件 as Debug\main\main.pdb、 project basDebug\b\b.pdb等等。

Finally, in Linker -> Debuggingsettings of project mainthe Generate Program Database Filevalue is set to $(OutDir)$(TargetName).pdb. This means that the global PDB file for the entire executable will be generated as Debug\main.pdb.

最后,在Linker -> Debugging项目设置中main将该Generate Program Database File值设置为$(OutDir)$(TargetName).pdb。这意味着整个可执行文件的全局 PDB 文件将生成为Debug\main.pdb.

Note that in this setup each PDB file is generated in its own, separate directory.

请注意,在此设置中,每个 PDB 文件都在其自己的单独目录中生成。

In this setup you will get Debugging information cannot be found or does not matcherror if you attempt to run the program under the debugger. And if you take a look at the Debug\main.pdbfile (which will exist), you will notice that it is exactly the same as Debug\main\main.pdbfile! I.e. somehow the local PDB for mainmanaged to overwrite what was supposed to be the global PDB for the final executable. I.e. the debugger is right to complain that the PDB file is "wrong". It is indeed wrong.

在此设置中,如果您尝试在调试器下运行程序,您将收到无法找到调试信息或不匹配错误。如果您查看Debug\main.pdb文件(将存在),您会注意到它与Debug\main\main.pdb文件完全相同!即不知何故,本地 PDBmain设法覆盖了最终可执行文件的应该是全局 PDB 的内容。即调试器抱怨 PDB 文件“错误”是正确的。这确实是错误的。

Again, in the above setup the final global PDB somehow gets overwritten by local PDB of the top project. I don't know why it happens. It appears to be a bug. (Note that even though these PDB files have the same name, they are generated in different directories, i.e. they should not conflict.)

同样,在上述设置中,最终的全局 PDB 不知何故被顶级项目的本地 PDB 覆盖。我不知道为什么会这样。这似乎是一个错误。(请注意,即使这些 PDB 文件具有相同的名称,它们也是在不同的目录中生成的,即它们不应冲突。)

A workaround that fixes this issue is to give the local PDB of project maina different name. For example, just go to C/C++ -> Output Filesfor the mainproject and change Program Database File Namevalue to $(IntDir)$(TargetName)_local.pdb(or to $(IntDir)12345.pdbif you so desire). This will eliminate the conflict and solve the problem.

解决此问题的解决方法是为项目的本地 PDBmain指定不同的名称。例如,刚去C/C++ -> Output Filesmain项目和变化Program Database File Name$(IntDir)$(TargetName)_local.pdb(或者$(IntDir)12345.pdb,如果你愿意的话)。这将消除冲突并解决问题。

回答by vasquez

Enable PDB creation by:

通过以下方式启用 PDB 创建:

Right click on MyProject > Properties > Debugging:

右键单击MyProject > Properties > Debugging

  • C/C++ > General > Debug Information Output = Program Database (/Zi)
  • Linker > Debugging > Generate Debug Info = Yes (/DEBUG)
  • C/C++ > General > Debug Information Output = Program Database (/Zi)
  • Linker > Debugging > Generate Debug Info = Yes (/DEBUG)

Clean MyProject, restart Visual Studio (just to be sure), rebuild MyProject. The output folder should then contain *.pdb files.

清理 MyProject,重新启动 Visual Studio(只是为了确定),重建 MyProject。然后输出文件夹应包含 *.pdb 文件。

If you debug optimized/release code consider switching off optimization via

如果您调试优化/发布代码,请考虑通过以下方式关闭优化

  • C++ > Optimization > Optmization = Disabled (/Od)
  • C++ > Optimization > Optmization = Disabled (/Od)

回答by Piyush_Jain

I faced the same problem and tried all above mentioned solutions but it couldn't help me. Then I found a new solution randomly and it worked.

我遇到了同样的问题并尝试了上述所有解决方案,但它无法帮助我。然后我随机找到了一个新的解决方案并且它起作用了。

Solution is that,in case you are having many projects in a solution then you should mark any one (specific one which you have to decide) project as a "Set as Startup Project". Right click on that specific project and click "Set as Startup Project".

解决方案是,如果您在一个解决方案中有许多项目,那么您应该将任何一个(您必须决定的特定项目)标记为“设置为启动项目”。右键单击该特定项目,然后单击“设置为启动项目”。

It worked for me.

它对我有用。

回答by dirkgently

The pdbor Program Database file appears to be missing (basically, the path has changed and can no longer be found by the compiler). See thisrelated post for additional information.

pdb或程序的数据库文件似乎缺少(基本上,路径已经改变,不能再被编译器发现的)。有关其他信息,请参阅相关帖子。

回答by oliver

I had a similar problem and the reason was that I had run one of the projects of my solution in a different process and that process couldn't be killed. I didn't think much of it. So when I was building the solution in a separate environment one of the pdb files didn't match so at the end I couldn't load any of the pdb files. I just restarted my computer and that fixed it.

我遇到了类似的问题,原因是我在不同的进程中运行了我的解决方案的一个项目,并且无法终止该进程。我没有多想。因此,当我在单独的环境中构建解决方案时,其中一个 pdb 文件不匹配,因此最后我无法加载任何 pdb 文件。我刚刚重新启动了我的电脑并修复了它。

Good luck

祝你好运

回答by Vladimir Panteleev

Restarting Visual Studio can fix one instance of this problem.

重新启动 Visual Studio 可以解决此问题的一个实例。

回答by Yuri Feldman

Right click on your project in the solution browser => Clean => Build. That is if your build generates a .pdb at all (look in your target dir) If not, you should enable debug by the steps mentioned in other posts

在解决方案浏览器中右键单击您的项目 => Clean => Build。也就是说,如果您的构建完全生成 .pdb(查看您的目标目录)如果没有,您应该按照其他帖子中提到的步骤启用调试