none
Is there a way to tell if the C++ object code has changed? RRS feed

  • Question

  • When building a native C++ project under VS, is there any way to determine if the object code has changed? This will be used to increment a "build number".

    For example, if I change a comment in a .cpp file, I have changed the file, so a build will recompile that file, or at least check it ("no code changes detected" sometimes appears during a build), but the object code will not change. OTOH, if I change a line of code "x=y+z" to "x=y+1", the object code must change (assuming I hadn't defined z as a constant 1).

    VS2010 or VS2012, Win 7 64-bit

    Friday, July 26, 2013 10:51 PM

All replies

  • Hi,

    Please view: BuildNumber Seems like it will do what you want.

    Hope it can help you!

     

     


    Sophia Gou
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 30, 2013 2:52 AM
  • Please view: BuildNumber Seems like it will do what you want.

    It is true I am trying to get a build number. However, the project you reference increments the build number regardless of whether any object code has changed. In fact, I already wrote a program that does this.

    What I need is a way to have Visual Studio tell me which object files have changed, as I asked.

    Tuesday, July 30, 2013 6:18 AM
  • Sorry for my misunderstanding and thanks for your quick response to me!

    And Visual Studio Tip: Auto-refresh file changes should be valuable for your requirement.

    Please do some setting on VS (Below is with vs2012):

    Open [Tools]-[Options]-Documents..as below screenshot shows:Check the red part 'Auto-load changes, if saved'.

    Hope it can help you!


    Sophia Gou
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 30, 2013 8:47 AM
  • And Visual Studio Tip: Auto-refresh file changes should be valuable for your requirement.

    "File changes" refers to changes in the SOURCE files; I want to see only changes in the OBJECT files. See OP for an example.

    Also, auto-refreshing only loads the changed files. I need to detect changed object files programatically.

    Tuesday, July 30, 2013 4:56 PM
  • Hi VoiceOfExperience,

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    We will let you know if any progress is made. Sorry for any inconvenience.



    Sophia Gou
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 1, 2013 9:33 AM
  • There is no guarantee that the compiler will generate identical machine code for two builds done on identical code.

    The reason is explained here...

    http://support.microsoft.com/kb/164151

    Also the compiler adds a GUID to bind an exe and its corresponding pdb file whenever a build is done so that the debugger loads the correct PDB. So that's another change that get's into an executable.

    So you cannot use change in object code as a criteria to increment build number. Probably you can try with last modified date.


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.

    Thursday, August 1, 2013 8:25 PM
  • There is no guarantee that the compiler will generate identical machine code for two builds done on identical code.

    ...

    So you cannot use change in object code as a criteria to increment build number. Probably you can try with last modified date.

    I agree that the .exe isn't guaranteed to be identical, for several reasons. But change in object code can be used, in this sense: if all the object files and libraries which are linked to form the executable are unchanged, the executable will function identically, except in the rare case that the O/S itself has changed (perhaps by a patch).

    In order to use the timestamps on the objects, it is necessary to know that the object file isn't rebuilt if there is no change. The definition of "no change" in this case is simply that the object code is bit-for-bit the same.

    For example, if I change a comment, or change the name of a variable, the compiler should produce the same object code. With an optimizing compiler, even changes in the source code may have no effect in the object code.

    The idea is, increment the build number only if the .exe is capable of producing a different result on any possible input data.

    Thursday, August 1, 2013 8:51 PM
  • Hi,

    There is no inbuilt support in visual studio for this. Object code will not be same across builds.

    Nibu


    Blog: http://ntcoder.com/bab


    Posts are provided as is without warranties or guaranties.


    • Edited by Nibu Thomas Thursday, August 15, 2013 9:29 AM
    Thursday, August 15, 2013 9:29 AM