When co开发者_运维百科mpiling using G++ GNU compiler every time I do a build, without changing source code I get a different binary object file. Is there a compile option that will give me the same binary each time.
Copied from the GCC man-page:
-frandom-seed=string
This option provides a seed that GCC uses when it would otherwise use random numbers. It is used to generate certain symbol names that have to be different in every compiled file. It is also used to place unique stamps in coverage data files and the object files that produce them. You can use the -frandom-seed option to produce reproducibly identical object files.The string should be different for every file you compile.
You should better use make
. This way if your source didn't change, the compilation will be skipped, so the object files won't be changed.
Edit: after some thinking, it's possible to address your comment with the makefile which separates preprocessing and actual compilation. and some dirty tricks.
Example makefile:
all: source
source: source.i.cpp
@cmp -s source.i.cpp source.i.prev || g++ source.i.cpp -o source
@touch source
@cp source.i.cpp source.i.prev
source.i.cpp: source.cpp
@g++ -E source.cpp >source.i.cpp
Please note the the executable's time is changed, but the contents not (if you changed only the comments, not the actual code).
精彩评论