views:

90

answers:

3

Hi all,

I have a question about the source-code binary on Windows.

#include <stdio.h>

int main()
{
    printf("Hello, world!\n");

    return 0;
}

The same source code, I compiled twice on Windows (VS 2008 Cmmand Prompt: "CL"), but I got different binaries.

cl new.cpp

Can you guys tell me why, and how to avoid that? Thanks.

Peter

+1  A: 

Did you compile as release? Debug has timestamps built in which can change your exe per compile

Michael Dorgan
Compiling as directed above yielded a difference of exactly 1 byte. The LSB of the embedded timestamp.
mocj
+3  A: 

The timestamp is part of PE format. You'll always get different values regardless if compiling as release or not.

josuegomes
How can I avoid that? Is it possible to remove the timestamp? Because in Linux, if I use g++/gcc, the final binaries are the same.
Peter Lee
@Peter: ELF (Linux's executable format) does not have a timestamp field. Why does it matter if the output is different?
Billy ONeal
@Billy: You are right that ELF might not have the timestamp field. It's just very annoying that same source code different binaries.
Peter Lee
@Peter: Why is that annoying?
Billy ONeal
The only problem I see from this is if you're trying to debug a crash dump (aka core dumps). Windows debugging tools associate the dump with a binary checksum, so you can't debug the dump with a different binary, even if there is no code changes. Some tools can update the checksum in the dump file but usually this is not a good idea. BTW, I have no idea how does this work on Unix world.
josuegomes
+1  A: 

I googled, and found a mid-way solution:

DUMPBIN  /RAWDATA  MyApp.EXE > first.txt
DUMPBIN  /RAWDATA  MyApp.EXE > second.txt

http://support.microsoft.com/kb/164151 How to compare binary images of the same project builds

Peter Lee
@Peter Lee: You could also work around it by setting the timestamp to the same value in both executables.
Billy ONeal