使用cmake在文件末尾附加空字符 [英] append null character at the end of file using cmake

查看:144
本文介绍了使用cmake在文件末尾附加空字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cmake连接文件,并在输出文件末尾附加一个空字符( \0 )。有人知道如何在末尾附加null吗?
concat的代码为:

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()

要附加'\ 0'最后我尝试了以下方法:

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)

但这3个都不起作用。有人可以在这里提供帮助吗?

But none of these 3 work. Can anyone help here ?

推荐答案

您能尝试以下方法吗?

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

这篇关于使用cmake在文件末尾附加空字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆