0

I would like to include the content of some binary files in a statically linked C++ project - for context, these are payloads to be sent to vendor hardware devices.

Consequently I would like to end up at compile time with the content and length of files (whose paths are determined at compile time) in vector<uint8_t>s and size_ts, for instance.

What's the best way to do this ?

For the record, a fairly similar question was asked here, however, while there's always the option of using a script to convert each byte of the binary file to its numeric representation so I can later include it as part of a generated source code file, I was hoping there may be common support for some more natural way to do this.

Thanks.

6
  • You can use #embed, q.v. stackoverflow.com/a/73570472/4641116 Commented Sep 2, 2022 at 21:04
  • Damn, that seems to be C-specific. Though I guess I could codegen C and include it in my C++ project. Either way it seems my question is a duplicate of that one, that I hadn't found. Thanks for the link ! Commented Sep 2, 2022 at 21:06
  • There is std::embed proposal Commented Sep 2, 2022 at 21:18
  • From what I'm reading, it's not going well... thephd.dev/full-circle-embed Commented Sep 2, 2022 at 21:19
  • This is how to include a binary file in your C++ program, consisting of three bytes, 1, 2, and 3: static const char binaryfile[3]={0x01,0x02,0x03};. That's my binary file. This will work for binary file of any size. Commented Sep 2, 2022 at 21:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.