arduino / arduino/ArduinoCore-avr
Arduino.h and avr stdlib "conflicting declaration of C function"
- Dominant language
- C
- Stars
- 1.5k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
# Context
I'm working to get a Visual Studio Code Devcontainer up and running with a Bazel build for [Arduboy](https://www.arduboy.com/). I've pushed my current (problematic - per this GH issue) effort to my [arduboy_bazel repo](https://github.com/electronjoe/arduboy_bazel/tree/7b72a607f3eaf6027f18171bdf4cbc2587421543).
If you wanted to play with it you could:
- Check out the repo
- Install Docker Desktop
- Open directory in VS Code and install the VS Code [Remote - Containers extension](https://code.visualstudio.com/docs/remote/containers-tutorial)
- Restart vs code?
- `F1` -> `Remote-Containers: Rebuild and open in Container`
- Wait for the container to build
- Open terminal in VS Code
- `bazel build //example:buttons --config=avr --verbose_failures --sandbox_debug`
- Or for verbose action output
- `bazel aquery //example:buttons --config=avr --verbose_failures --sandbox_debug`
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](https://github.com/electronjoe/arduboy_bazel/blob/main/example/buttons.cpp).
# Versions
- I'm installing all `avr tooling` & `stdlib` using the `github.com/arduino/toolchain-avr` repo branch `7.3.0-atmel3.6.1-arduino7` [See here](https://github.com/electronjoe/arduboy_bazel/blob/main/.devcontainer/Dockerfile#L25-L36)
```
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.
```
- I'm using `github.com/arduino/ArduinoCore-avr` at tag `1.8.5` [See here](https://github.com/electronjoe/arduboy_bazel/blob/main/deps.bzl#L56-L63)
# 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](https://gist.github.com/electronjoe/879a6425284576b90b22fd8a0b105db7).
# 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!
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the Bazel AVR build for //example:buttons using the command shown, then inspect cores/arduino/main.cpp, Arduino.h around line 132, and the AVR stdlib.h declaration at line 685. Compare the additional errors in the linked full-error gist and determine the intended compatible declarations; done means the example builds without these conflicting-declaration errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- arduino, c, cpp, docker
- Domain
- build-system, embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 32/100