跳转到内容
彼岸论坛
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[C] 将资源嵌入到可执行文件中并保持目录结构


小天管理

已推荐帖子

保持目录结构可以方便根据路径查找使用.

  • bash 脚本用来生成 .c 文件
chmod +x embed_file_c.sh

./embed_file_c.sh dir2c_test
# or
./embed_file_c.sh dir2c /path/to/resource > _data_enc.c
gcc embed_file.c -o embed_file
./embed_file
  • 生成的 .c 文件这样使用
#include <stdio.h>
#include <stdint.h>
int main(int argc, char *argv[]) {
	#define _DATA_ENC_INC 1
	#include "_data_enc.c"
	for (int i = 0; i < sizeof(_data_enc_lst)/sizeof(_data_enc_lst[0]); ++i) {
		printf("%3u, %3u, %s\n", _data_enc_lst[i].off, _data_enc_lst[i].len, _data_enc_lst[i].path);
		// &_data_enc[_data_enc_lst[i].off] is the data ptr, use it by need
	}
	return 0;
}

代码 https://github.com/webd90kb/webd/tree/master/codes/scripts/embed_file_c

意见的链接
分享到其他网站

加入讨论

您现在可以发表并稍后注册. 如果您是会员,请现在登录来参与讨论.

游客
回复主题...

×   粘贴为富文本.   粘贴为纯文本来代替

  只允许使用75个表情符号.

×   您的链接已自动嵌入.   显示为链接来代替

×   您之前的内容已恢复.   清除编辑器

×   您无法直接粘贴图片.要从网址上传或插入图片.

  • 游客注册

    游客注册

  • 会员

    没有会员可显示

  • 最新的状态更新

    没有最新的状态更新
  • 最近查看

    • 没有会员查看此页面.
×
×
  • 创建新的...