Espressif32 platform and `bars`?

Short question:
Do you have any idea what can be causing multiple definition error when trying to declare int bars; in a global scope?

Detailed explanation:
Code in main.cpp looks like this:

#include <Arduino.h>
int bars, bar, bars2;
void setup() {}
void loop() {}

Platformio settings in platformio.ini:

[env]
framework = arduino

[env:main]
platform = espressif32
board = esp32doit-devkit-v1

And when I try to build I get following multiple definition error:

/home/vovo/.platformio/packages/toolchain-xtensa-esp32/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld: /home/vovo/.platformio/packages/framework-arduinoespressif32/tools/sdk/esp32/lib/libpp.a(pp.o):(.dram1.4+0x0): multiple definition of `bars’; .pio/build/main/src/main.cpp.o:/…/src/main.cpp:2: first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/main/firmware.elf] Error 1

There is no problem with bar or bars2 but the compiler does not like the definition of bars for some reason.
When I change platform = atmelavr and board = uno in platformio.ini, the project compiles without any error. So the problem is probably with espressif32 platform.
When I do not declare bars then I get not declared in this scope error when I try to access this variable. So it is not an imported var or function. Definition within setup() works well.
Same error appears on two different computers so it should not be related to some cached settings etc.

I know, I can use different names for my variable but I am pretty sure it worked for me a few months ago.
I tried to upgrade pio but pio --version returns PlatformIO Core, version 6.1.5 which should be the latest version.

There is probably something stuping I am doing wrong but I am not able to figure out what it is.

Thanks

The error message tells you right there that bars is defined in the libpp.a library of Arduino-ESP32.

>nm C:\Users\Max\Downloads\libpp.a | grep -B1 -A5 bars
pp.o:
00000000 D bars
00000000 D CanDoFreqCal
         U config_get_wifi_task_core_id
         U config_get_wifi_task_stack_size
         U config_is_cache_tx_buf_enabled
00000000 B CurFreeSigIdx

Since you write

You are creating a global variable, and so your variable name must be distinct from all other existing global variables, no matter whether they are created in the SDK or in your code.

This problem would have been avoided if you

  • used a more unique name
  • used static int instead of int to make the files visible in only the current file. This only works if you need direct variable access in this file and don’t share it with another .cpp file.