Jeija / esp32-softap-ota

Minimal esp-idf example of HTTP portal to perform OTA updates of ESP32 in SoftAP mode
MIT License
57 stars 16 forks source link

Error: C99 designator 'ssid' outside aggregate initializer #1

Open G1tz2029 opened 1 month ago

G1tz2029 commented 1 month ago

Hello,

I've run into some trouble trying to compile this code. I'm getting an error: C99 designator 'ssid' outside aggregate initializer. I initially thought this was because I was using an older version of GCC but even after updating to the latest I'm still seeing the error.

Some background. I'm using PlatformIO and VSCode as my IDE. My main project is C++ and I have your code in an "extern". No other errors.

Full error:

src/main.cpp: In function 'esp_err_t softap_init()': src/main.cpp:122:153: error: C99 designator 'ssid' outside aggregate initializer wifi_config_t wifi_config = {.ap = {.ssid = WIFI_SSID, .ssid_len = strlen(WIFI_SSID), .channel = 6, .authmode = WIFI_AUTH_OPEN, .max_connection = 3}};

Jeija commented 1 month ago

This is the key issue I believe:

My main project is C++ and I have your code in an "extern". No other errors.

Writing extern "C" changes they way function names are linked, but it doesn't change the programming language. You are still compiling this project (C code) with a C++ compiler. While C has supported designated initializers for structs for a long time, C++ added support only recently with C++20. This is not a matter of the GCC version, but a matter of telling GCC which C++ standard to use.

So I think the most reasonable options are:

G1tz2029 commented 1 month ago

Thanks for getting back to me. I will give this a shot! Do you have an example I can read up on using an initializer list if I can't get my IDE to use a newer C++ standard?

Jeija commented 1 month ago

I think this StackOverflow question and the corresponding answers are some pretty good, basic examples for how to initialize a struct in C++: https://stackoverflow.com/questions/11516657/c-structure-initialization

G1tz2029 commented 1 month ago

Looks like that did the trick for that error. No more C99 C++ error.

I'm now looking at quite a few warnings and a somewhat generic sounding error: collect2.exe: error: ld returned 1 exit status which sounds like previous "warning" errors caused it. It is odd because I'm not actually seeing any errors, just warnings.

image

Jeija commented 1 month ago

You have two linker errors:

esp32-softap-ota embeds the webpage (https://github.com/Jeija/esp32-softap-ota/blob/master/main/web/index.html) into the firmware as a binary blob. This is done using EMBED_TXTFILES in https://github.com/Jeija/esp32-softap-ota/blob/master/main/CMakeLists.txt You need to figure out how to set EMBED_TXTFILES (or something equivalent) in your build system.

G1tz2029 commented 1 month ago

Wow, I really should have been able to catch both of those even if I don't know C/C++ very well (I'm a front end guy trying to get my bearings). This is so helpful. My project is written for an Arduino, so it has a setup() and loop() within my main.cpp. It sounds like I need to do something like this:

void app_main() {
  // Arduino setup logic
  for (;;) {
    // Arduino loop logic
  }
}

The index.html file I completely overlooked so I'll need to figure out how to get that re-embedded. Thanks again for getting me this far.