Page 1 of 1

How to embed files in C++?

PostPosted: Fri Oct 07, 2022 6:57 pm
by felfert

I am using the ESP8266_RTOS_SDK trying to write my first app.

I use the COMPONENT_EMBED_TXTFILES feature in the component.mk to embed some certificate (PEM).
The following code then embeds the certificate and corresponding key:

Code: Select allstatic uint8_t d_client_crt_start[] asm("_binary_client_crt_start");
static uint8_t client_crt_end[]   asm("_binary_client_crt_end");
static uint8_t client_key_start[] asm("_binary_client_key_start");
static uint8_t client_key_end[]   asm("_binary_client_key_end");

When I put this code in a .c file, it works flawlessly, however if this is in a .cpp file, i get the following
error during compilation:

Code: Select allapp.cpp:45:16: error: storage size of 'client_crt_start' isn't known
 static uint8_t client_crt_start[] asm("_binary_client_crt_start");

For now, I have put the embedding code into a separate .c file but I really would like to have it
in the main app.cpp. I am unfamiliar with using gcc's asm(...) in C++, so I would appreciate
any help here.


Re: How to embed files in C++?

PostPosted: Tue Oct 11, 2022 11:40 pm
by Pablo2048
You can try this:
Code: Select allextern "C"

// your definitions here


Re: How to embed files in C++?

PostPosted: Wed Oct 12, 2022 4:09 am
by felfert
That was my first idea, but it produces the same error.
Sorry I forgot to mention it.

Thanks anyway