Is it possible to add library based on arduino memory variable?

#include <nvs_flash.h>
#include <Preferences.h>//Flash memory library
Preferences preferences_object;

int abc=preferences_object.getInt("baglantituru", 1); //I need to call the variable in the flash memory of the ESP32, if this variable is 1, the ethernet card will be activated, if it is 2, wifi will be activated.

#if abc==2
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#else
#include <SPI.h>
#include <Ethernet2.h>
#include <BlynkSimpleEthernet2.h>
#endif


According to the value of the variable written in the ESP32 flash memory, wifi or ethernet should be active on the card, but I could not run the #if statement except for #define. I keep getting errors. Is there a method to do this? Thanks.....

The condition you test must be a compile-time constant (a value known when your sketch is compiled). If you want to make the decision based on run-time data, you have to load both sets of libraries and write your code to use the right library.

Since two libraries contain similar data, there is a conflict and it gives an error (#include <BlynkSimpleEsp32.h> , <BlynkSimpleEthernet2.h>) for this reason, I wanted to load only one of them, but I guess there is no way, I couldn't make the library selection except for defining a constant with #define

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.