Gnu+11 or what do I need to compile this sample code?

I’m trying to compile some sample code for ESP32. I assume this code compiles under ESP-IDF, and I would like it to compile under PlatformIO.

Here is the code:

  wifi_config_t wifi_config = {
      .sta =
          {
               .ssid = ssid,
               .password = password,
              .threshold.authmode = WIFI_AUTH_WPA2_PSK,
              .pmf_cfg = {.capable = true, .required = false},
          },
  };

I get an error when the ssid and password fields are being copied in, and another when setting .threshold.authmode

It compiles if I made the following changes:

  wifi_config_t wifi_config = {
      .sta =
          {
              .threshold = {
                .authmode = WIFI_AUTH_WPA2_PSK,
              },
              .pmf_cfg = {.capable = true, .required = false},
          },
  };
strcpy((char *)wifi_config.sta.ssid, ssid);
strcpy((char *)wifi_config.sta.password, password);

I’m assuming that the sample code works as-is, and would like to figure out what I need to do to make it work using PlatformIO.

I already have this build flag:

build_flags = 
    -std=gnu++11

Yeah but did they write in a .c or .cpp file?

You’re right! I didn’t notice this. They wrote it in .c and I am trying to use it in .cpp.

I see the problem. I’m curious, why is it that C++ isn’t offering some of the niceties of C?

¯_(ツ)_/¯ I wouldn’t know.

1 Like