The only way I know how to do this is to convert the file into a C source file with a single byte/char array containing the contents of the resource file in hex.
Is there a better or easier way to do this?
Here's a nice trick I use with a gcc-arm cross compiler; including a file through an assembly language file. In this example it's the contents of the file public_key.pem
I'm including.
pubkey.s
.section ".rodata"
.globl pubkey
.type pubkey, STT_OBJECT
pubkey:
.incbin "public_key.pem"
.byte 0
.size pubkey, .-pubkey
corresponding pubkey.h
#ifndef PUBKEY_H
#define PUBKEY_H
/*
* This is a binary blob, the public key in PEM format,
* brought in by pubkey.s
*/
extern const char pubkey[];
#endif // PUBKEY_H
Now the C sources can include pubkey.h
, compile the pubkey.s
with gcc and link it into your application, and there you go. sizeof(pubkey)
also works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With