I have a numerical C++ model of thousands of LOC that outputs different results on different machines and I want to fully understand why that is. Those differences start out in like the 14th significant digit but then propagate to produce quite different results.
I've spent many days on this now and I finally came to this point: When I build it on my machine and copy it to machine B, I can get the exact same results on both machines if I compiled it via
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static" -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" ..
So that is already great. But I want to know more specifically what causes the differences. So I checked which libraries are possible culprits:
$ ldd my_software
linux-vdso.so.1 (0x00007ffdbd99c000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f08720b4000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0871d16000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f0871afe000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f087170d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0872724000)
So my idea was that I would ideally find one library that changes it and then think about what part of this library that is and if I can do something about this.
Only linking a single library statically worked for, e.g., libgcc
:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static-libgcc" ..
But the results were still different. So that was not it. The problem now is, that I seem to not be able to link libc
or libm
statically:
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXE_LINKER_FLAGS="-static-libm" .. # works
cd ..
cmake --build statically_linked_m/ --target my_software
...
[100%] Linking CXX executable my_software
g++: error: unrecognized command line option ‘-static-libm’; did you mean ‘-static-libgo’?
So I am wondering, why can't I do that? I mean, it apparently got linked statically when I compiled it with the -DCMAKE_EXE_LINKER_FLAGS="-static" -DCMAKE_FIND_LIBRARY_SUFFIXES=".a"
flags. So why is this not working?
I hope I made my issue clear. Any pointers are highly appreciated!