问题
I am trying to concatenate files using cmake and append a null character(\0
) at the end of output file. Does anyone know how to append null at the end?
The code for concat is :
function(cat in_file1 in_file2 out_file)
file(READ ${in_file1} CONTENTS)
file(WRITE ${out_file} "${CONTENTS}")
file(READ ${in_file2} CONTENTS)
file(APPEND ${out_file} "${CONTENTS}")
endfunction()
To append '\0'
at the end I've tried following approaches :
file(APPEND ${out_file} NULL)
file(APPEND ${out_file} "\\0")
file(APPEND ${out_file} "\0" HEX)
But none of these 3 work. Can anyone help here ?
回答1:
Could you try the following instead of what you have?
function(cat in_file1 in_file2 out_file)
file(READ ${in_file1} CONTENTS HEX)
file(WRITE ${out_file} "${CONTENTS}")
file(READ ${in_file2} CONTENTS HEX)
file(APPEND ${out_file} "${CONTENTS}00")
endfunction()
this should append a null byte at the end of the generated hex string. Then I don't know how to go from there.
There is some work in this direction but I don't know other examples. I think both the linked examples can be useful to solve your case:
binary_to_hex
embed_binary_files
来源:https://stackoverflow.com/questions/41514723/append-null-character-at-the-end-of-file-using-cmake