none
Visual Studio 2017: Adding a custom debugging data visualizer (.natvis) file causes a perpetual mismatch between precompiled headers and the .pdb file RRS feed

  • Question

  • Hi, I am trying to add some custom data visualizers to help with debugging our c++ code.  I added the file 'NatVisFile.natvis' to my project, which will contain the custom visualizers.  Now, every time I make a small change to my code, for example to 'miximage.cpp' I have to recompile everything, otherwise I get the error message below:

    "miximage.cpp(5): error C2859: myprogram.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.

    1>Done building project "myprogram.vcxproj" -- FAILED."

    I have rebuilt my program database files and all pch files, but the problem persists.

    Any ideas?

    Thanks, Jon
    • Edited by jba999 Tuesday, April 24, 2018 5:02 PM
    Tuesday, April 24, 2018 4:47 PM

All replies

  • Hi,

    thanks for posting here.

    >>"miximage.cpp(5): error C2859: myprogram.pdb is not the pdb file that was used when this precompiled header was created, recreate the precompiled header.

    Have you tried to set the project property or cpp file property->C/C++->Precompiled Headers->Precompiled Header to Create (/Yc)?

    Use /Yc to create a precompiled header. When used with the optional hdrstop pragma, /Yc lets you precompile both header files and source code.

    Here is a document about precompiled header file, you could refer to it.

    https://docs.microsoft.com/en-us/cpp/build/reference/creating-precompiled-header-files

    Hope this could be help of you.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 25, 2018 1:49 AM
  • Hi Baron,

    Thanks for the answer.  We essentially use the original visual studio precompiled header setup for c++ projects, we have everything we want precompiled in 'stdafx.h', and use /Yc on 'stdafx.cpp' to create the precompiled header.  All other source files are compiled '/Yu'.  That said, I created another small c++ project with multiple source files in an attempt to reproduce this problem and was not successful.

    Maybe I'm not understanding how I should change this but I hate to have to change this build configuration just so we can have custom visualizers to help with some native code debugging.

    Best Wishes,
    Jon

    Wednesday, April 25, 2018 10:01 PM
  • >>All other source files are compiled '/Yu'.  That said, I created another small c++ project with multiple source files in an attempt to reproduce this problem and was not successful.

    So have you tried to change these source files which compiled with /Yu to /Yc?

    The /Yu compiler option instructs the compiler to use an existing precompiled header (.pch) file in the current compilation. That may not match the pdb file.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, April 27, 2018 8:26 AM
  • Hi,

    Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Baron Bi


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 7, 2018 7:45 AM
  • Happens here too since I included the NATVIS file into the project.

    I cannot find a workaround, though. Crazy.

    Might it be that the NATVIS is built into the PDB (although the command line does not have the /NATVIS switch)? And that this somhow confused the PCH file check?
    • Edited by chksr Thursday, January 3, 2019 4:23 PM
    Thursday, January 3, 2019 4:21 PM
  • I’ve been using natvis for a long time now, without including the file in the project. Recently, I started porting from 32 to 64, and as part of that effort I thought it’d be a good idea to include the natvis file in the project. Then I started getting the problem that affects you. I thought it had to do with the interaction between the 32 and 64 bit configurations, but the cause was simply that the natvis file was now part of the project: I removed it and the problem went away.

    Now, what I’d like to know is this: these MSDN certified experts who try so hard to give you any advice they can come up with, whatever, in order to accumulate more points: what are they planning to buy with those points?

    Monday, February 4, 2019 6:30 PM