Skip to content

Including "Arduino.h" across multiple object files redefines 'main' #2

@MichaelMGonzalez

Description

@MichaelMGonzalez

I tried compiling an existing Arduino library with the following commands

g++  -c at86rf2xx.cpp
g++  -c at86rf2xx-internal.cpp
g++  -c at86rf2xx-getset.cpp
g++ -x c++ -c arduino-at86rf233.ino
g++ -lpiduino -o test_radio at86rf2xx.o at86rf2xx-internal.o at86rf2xx-getset.o arduino-at86rf233.o

g++ gave me the following erros

at86rf2xx-internal.o: In function `main':
at86rf2xx-internal.cpp:(.text+0x0): multiple definition of `main'
at86rf2xx.o:at86rf2xx.cpp:(.text+0x0): first defined here
at86rf2xx-getset.o: In function `main':
at86rf2xx-getset.cpp:(.text+0x0): multiple definition of `main'
at86rf2xx.o:at86rf2xx.cpp:(.text+0x0): first defined here
arduino-at86rf233.o: In function `main':
arduino-at86rf233.ino:(.text+0x0): multiple definition of `main'

Inspecting the assembly showed that a main label was created for each object file

Within piduino's Arduino.h file, it seems to provide a full definition for main().

https://github.com/NVSL/PiDuino_Library/blob/master/Arduinoh/Arduino.h#L36

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions