while trying to compile this program with scons, we faced this error
build/opt/zsim_harness.cpp:315:5: error: stray \'\\\' in program
build/opt/zsim_harness.cpp:
The problem is that the Python code has too many backslashes in this line:
'echo "#define ZSIM_BUILDDATE \\""`date`\\""\\\\n#define ZSIM_BUILDVERSION \\""no git repo\\""" >>' + versionFile)
This is being parsed by one less program that the code expects, so it ends up that '\\n' ends up in the file as the two characters '\' and 'n', rather than being parsed into a single newline character. The code is trying to avoid Python inserting the newline, which would break the shell command, and instead pass the escape sequence to the shell for it to change to a newline. Python provides an easier way to do this in the form of raw strings:
r'echo "#define ZSIM_BUILDDATE \""`date`\""\\n#define ZSIM_BUILDVERSION \""no git repo\""" >>' + versionFile)
and when it's put like this, you can see the error more clearly: the shell sees the escape sequence '\', so it prints a single \, followed by an n, rather than the escape sequence '\n' which would cause it to put a newline in the file.