將二進制文件加到C源碼中的工具包:incbin.bat

cf46d 10年前發布 | 22K 次閱讀 C/C++開發 incbin.bat

有時你需要將二進制數據嵌入至C / C++程序。 INCBIN是一個跨平臺的工具,剛好用來做到這一點。不像其他的解決方案,INCBIN是使用操作系統已經搭載的部件,所以不需要安裝第三方工具。它是跨平臺的,并且同樣適用于Windows和UNIX系統。

Example usage:

Windows:      incbin.bat myfile.bin output.h foo
UNIX:         sh incbin.bat myfile.bin output.h foo

(where 'foo' is the C symbol name you want the data stored in)

Further usage

Here's an example showing how to callincbinfrom a Makefile:

all : foo.h

SCRIPTSHELL := $(if $(findstring $(OS),Windows_NT),cmd /c,sh)

foo.h : test.png $(SCRIPTSHELL) incbin.bat $< $@ foo</pre>

Output format

Here's an example of the kind of output you get:

incbin.bat test.bin foodata.h foo

/ Generated by incbin /

include <stddef.h>

const unsigned char foo_data[] = { /00000000/ 0x40,0x65,0x63,0x68,0x6F,0x20,0x6F,0x66,0x66,0x0D,0x0A,0x22,0x43,0x3A,0x5C,0x50, /00000010/ 0x72,0x6F,0x67,0x72,0x61,0x6D,0x20,0x46,0x69,0x6C,0x65,0x73,0x20,0x28,0x78,0x38, /00000020/ 0x36,0x29,0x5C,0x4D,0x69,0x63,0x72,0x6F,0x73,0x6F,0x66,0x74,0x20,0x56,0x69,0x73, /00000030/ 0x75,0x61,0x6C,0x20,0x53,0x74,0x75,0x64,0x69,0x6F,0x20,0x39,0x2E,0x30,0x5C,0x56, /00000040/ 0x43,0x5C,0x62,0x69,0x6E,0x5C,0x76,0x63,0x76,0x61,0x72,0x73,0x33,0x32,0x2E,0x62, /00000050/ 0x61,0x74,0x22,0x0D,0x0A };

const size_t foo_size = sizeof(foo_data);</pre>

項目主頁:http://www.baiduhome.net/lib/view/home/1422783944267


 本文由用戶 cf46d 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!