arduino / ArduinoCore-avr

The Official Arduino AVR core
https://www.arduino.cc
1.25k stars 1.06k forks source link

Arduino.h and avr stdlib "conflicting declaration of C function" #475

Open electronjoe opened 2 years ago

electronjoe commented 2 years ago

Context

I'm working to get a Visual Studio Code Devcontainer up and running with a Bazel build for Arduboy. I've pushed my current (problematic - per this GH issue) effort to my arduboy_bazel repo.

If you wanted to play with it you could:

Alternatively you can dev entirely in the cloud and skip the vs code install / extension install by using the (free for ~40 hours per month) gitpod.io in your browser, point it at my repo.

I'm having trouble getting past the following compiler error in building an example Arduboy demo I've copied into my repo (buttons.cpp) see ref.

Versions

vscode ➜ /workspaces/arduboy_bazel (main ✗) $ /home/vscode/toolchain-avr/objdir/bin/avr-g++ --version
avr-g++ (GCC) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Compilation Command

bazel build //example:buttons --config=avr --verbose_failures --sandbox_debug

/home/vscode/toolchain-avr/objdir/bin/avr-g++ -MD -MF bazel-out/avr-fastbuild/bin/example/_objs/buttons/main.d '-frandom-seed=bazel-out/avr-fastbuild/bin/example/_objs/buttons/main.o' -iquote . -iquote bazel-out/avr-fastbuild/bin -iquote external/arduboy2 -iquote bazel-out/avr-fastbuild/bin/external/arduboy2 -iquote external/arduinocore_avr -iquote bazel-out/avr-fastbuild/bin/external/arduinocore_avr -iquote external/bazel_tools -iquote bazel-out/avr-fastbuild/bin/external/bazel_tools -isystem external/arduboy2/src -isystem bazel-out/avr-fastbuild/bin/external/arduboy2/src -isystem external/arduinocore_avr/cores/arduino -isystem bazel-out/avr-fastbuild/bin/external/arduinocore_avr/cores/arduino -isystem external/arduinocore_avr/variants/leonardo -isystem bazel-out/avr-fastbuild/bin/external/arduinocore_avr/variants/leonardo -isystem external/arduinocore_avr/libraries/EEPROM/src -isystem bazel-out/avr-fastbuild/bin/external/arduinocore_avr/libraries/EEPROM/src '-mmcu=atmega32u4' '-DF_CPU=16000000L' '-DARDUINO=10819L' -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR '-DUSB_VID=0x2341' '-DUSB_PID=0x8036' '-DUSB_MANUFACTURER="Arduboy"' '-DUSB_PRODUCT="Arduboy_FX"' -g -Os -w '-std=gnu++11' -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics '-Wno-error=narrowing' -flto -w -x c++ -CC -c external/arduinocore_avr/cores/arduino/main.cpp -o bazel-out/avr-fastbuild/bin/example/_objs/buttons/main.o

Error

In file included from external/arduinocore_avr/cores/arduino/main.cpp:20:0:
external/arduinocore_avr/cores/arduino/Arduino.h:132:5: error: conflicting declaration of C function 'int atexit(void (*)(...))'
 int atexit(void (*func)()) __attribute__((weak));
     ^~~~~~
In file included from external/arduinocore_avr/cores/arduino/Arduino.h:23:0,
                 from external/arduinocore_avr/cores/arduino/main.cpp:20:
/home/vscode/toolchain-avr/objdir/avr/include/stdlib.h:685:12: note: previous declaration 'int atexit(void (*)())'
 extern int atexit(void (*)(void));
            ^~~~~~

And many more with similar root cause - Full errors.

Thoughts

Are there conflicting function declarations for a number of avr stdlib functions, redefined in arduinocore_avr's Arduino.h?

Is my compilation mistreating C / C++ headers in some way?

Do you see anything I'm doing wrong here?

Thanks for any assistance!