Browse - Programming Tips - How can I easily include a binary file in my code?

Date: 2016jan2
Language: C/C++

Q.  How can I easily include a binary file in my code?

A.  Use the xxd command with --include option:

xxd --include example.data
When file example.data contains "example\n" you get:
unsigned char example_data[] = { 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x0a }; unsigned int example_data_len = 8;
So, of course you can do:
xxd --include example.data > example.cpp
Perhaps in a Makefile