1 Star 0 Fork 0

10km / bin2c

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

bin2c - A simple utility for converting a binary file to a c application which can then be included within an application.

Usage:

bin2c input_file output_file array_name

for example, using:

bin2c my_file.dat my_file.h data

will create something along the lines of

const char data[3432] = {
   0x43, 0x28, 0x41, 0x11, 0xa3, 0xff,
   ...
   0x00, 0xff, 0x23
};

const int data_length = 3432;

This can then be used within your application, for example with SDL you would use SDL_RWops. The application can also be used in a very similar fashion to Qt's RC system.

I haven't included a Makefile because the utility is SO simple, I don't think that one is needed. But for an example, compiling for GNU/Linux can be done as shown

gcc -o bin2c bin2c.c

In the current system, you can tell bin2c to compress the data with BZ2 compression. This would be very useful in applications where a lot of files are stored this way or if memory is tight (although not CPU). To produce an executable which can make bz2 files, define USE_BZ2. However, since this is such a simple application, you can either define USE_BZ2 or not and it will then produce compressed data or not. An example as to how to compile a BZ2 compression version of bin2c is as such

gcc -o bin2cbz2 bin2c.c -DUSE_BZ2 -lbz2

This will add an extra constant, data_length_uncompressed, which is the size of the file before it was compressed. So to decompress the file, you would do something like the following:

unsigned int decompressed_size = data_length_uncompressed;
char *buf = malloc(data_length_uncompressed);
int status;

status = BZ2_bzBuffToBuffDecompress(buf, &decompressed_size,
        const_cast<char *>data, (unsigned int)data_length, 0, 0);

// do something with buf
free(buf);

I'm not entirely happy with having to do const_cast in C++ so if anyone can suggest an alternative then I'd be happy to implement it.

Patches are welcome, just fork the project on github and send me a pull request. If you are unable or unwilling to do this through github, then feel free to email me your patch. This utility is so small I don't think that any licence is needed, and I took most of the code from Serge Fukanchick and made quite a few modifications so left it in the public domain. So please just send me a little note to say that you don't mind your code being in the public domain.

conan support

bin2c support conan install

$ cd bin2c
# build 
$ conan create .
# upload to remote repository ${repo}
$ conan upload bin2c/1.0.0@ -r ${repo} --all

空文件

简介

fork from https://github.com/gwilymk/bin2c.git 将二进制资源文件生成.c或.h源码 生成的源码编译出的obj与gnu-ld -r -b binary -o binary_file.o binary_file 生成.o兼容,具有相同的符号表 展开 收起
C 等 4 种语言
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/l0km/bin2c.git
git@gitee.com:l0km/bin2c.git
l0km
bin2c
bin2c
master

搜索帮助