Is it possible to automate this with cmake?
You may want to checkout the CMRC library (CMake Resource Compiler) [0]. [0]: https://github.com/vector-of-bool/cmrc
Embedding Binary Objects in C
61–70 of 141 posts
Re: Embedding Binary Objects in C
#62Re: Embedding Binary Objects in C
#63Unfortunately, this technique is a bit problematic with modern C compilers. Because the `start` and `end` symbols are unrelated objects, as far as the compiler is concerned, the subtraction `&end - &start` to get the length of the data invokes undefined behavior. Just for that reason, I feel the include file with a hex dump is the better method.
Re: Embedding Binary Objects in C
#64Unfortunately, this technique is a bit problematic with modern C compilers. Because the `start` and `end` symbols are unrelated objects, as far as the compiler is concerned, the subtraction `&end - &start` to get the length of the data invokes undefined behavior. Just for that reason, I feel the include file with a hex dump is the better method.
Re: Embedding Binary Objects in C
#65My favorite is simply using a tool to create a C file with your binary data: static uint8_t mydata[] = {0xDE, 0xAD, 0xBE, 0xEF, ... }; The advantage is that it works anywhere, with any compiler. The disadvantage is that it can increase compile time. I would limit each .c file to 10MB; it seems there's a quadratic increase in build time with file size, at least with gcc. Also, instead of "0x%02x" I use decimal notatio…
I've never noticed the "quadratic" build time increase you mention, so I did a test[0]. Files in size from 1mb to 50mb, 3 trials each. These are the results, and they look absolutely linear[1]. [0]: https://pastebin.com/Z9329xkc [1]: https://i.imgur.com/I3XSBDg.png
Re: Embedding Binary Objects in C
#66Earlier quoted context omitted.
How exactly is the ordering of items across the section decided? Is it relatively random or is it based on the order that the object files are passed to the linker?
It's unspecified, and I've seen it change over time as the linker changes it's data structures.
Re: Embedding Binary Objects in C
#67There's also gnu's objcopy. This post covers a lot of different approaches, and has lots of tips: https://www.devever.net/~hl/incbin
The image background on that webpage is extremely distracting
Re: Embedding Binary Objects in C
#68I needed this last week! Building an embedded firmware image for a dashboard display, with lots of PNG files for icons etc. 61 of them. The original developer wrote a tool to expand the PNGs to BMPs (arrays of 32-bit pixel values) and generate a C array definition as a text file. Which is lots bigger than the original PNG (13K => 100K sort of thing). Then included that C source in the build. Used up 700K of my firmwa…
Nope. Dumb Visual Studio doesn't support embedded binary in cross-compile. That's the tool the client wanted, so I'm stuck with it. Funny, they (VisualGDB) even have a tutorial on doing it. But the option 'Embedded Resource' doesn't exist in my (modern) Visual Studio. Ha! And the feedback I gave VisualGDB about their outdated tutorial, they responded "Just pay HERE and we'll be glad to solve your problem!" They can g…
- hook custom tool calls
- link external objects into the project
Also, hello fellow automotive embedded SW eng! I know your suffering! :))
Re: Embedding Binary Objects in C
#69Re: Embedding Binary Objects in C
#70Totally not relevant for this post, but this is how we do this in Nim: const a = readFile("mydata") The `const` makes the expression evaluate at compile time, conveniently slurping the file into `a`, where it will be available at run time.