Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeatable object code generation c++

When I build a project using a c++ compiler, can I make sure that the produced binary is not affected if there were no changes in source code? It looks like everytime I recompile my source, the binary's md5 checksum is affected. Is the time of compilation somehow affecting the binary produced? How can I produce compilation results which are repeatable?

like image 336
user70336 Avatar asked Feb 24 '09 12:02

user70336


2 Answers

One can disassemble the binaries and run md5 on the output

Example on MacOSX

otool -tV a.out | md5
ee2e724434a89fce96aa6b48621f7220

But, one misses out on the global data...(might be a parameter to include too)

I'm answering on the problem of md5 checking a binary...how you manage your sources and build system as others have written about is also a thing to look at

like image 148
epatel Avatar answered Oct 04 '22 03:10

epatel


I suspect it'll heavily depend on your toolchain and OS. For example, if one of the executable headers contains a timestamp then you're always going to find the resulting MD5 is different.

What's the end result you're trying to achieve (ie why is it so important that they're identical)..?

like image 42
Sean Avatar answered Oct 04 '22 02:10

Sean