Linker Error re: digital_pin_to_PCMSK_bit_PGM

7 views
Skip to first unread message

Victor Aprea

unread,
Nov 24, 2015, 12:15:24 PM11/24/15
to Arduino Developers
Hi All,

Having a peculiar experience with the compiler and hoping others here can steer me in the right direction. I just discovered a bug in my pins_arduino.h for my core while trying to use SoftwareSerial, where the following #define was taking precedence over my own definitions.

#ifndef ARDUINO_MAIN
extern const uint8_t PROGMEM digital_pin_to_PCMSK_bit_PGM;
#endif

... so I removed that block of code and tried to replace it with my own definition of digital_pin_to_PCMSK_bit_PGM. But when I do that and try to compile a basic sketch, I get the following compile time output from the IDE.

/tmp/build4992724107852600463.tmp/core.a(wiring.c.o):(.progmem.data.digital_pin_to_PCMSK_bit_PGM+0x0): multiple definition of `digital_pin_to_PCMSK_bit_PGM'
/tmp/build4992724107852600463.tmp/core.a(wiring_digital.c.o):(.progmem.data.digital_pin_to_PCMSK_bit_PGM+0x0): first defined here
collect2: error: ld returned 1 exit status
Error compiling.

... so I went looking for where this pre-existing definition was, and doing the following command;

grep -r digital_pin_to_PCMSK_bit_PGM .

... from the root of my arduino folder (i.e. ~/arduino-1.6.5) returned no results. So I double checked and I didn't see any such definition in the suspected location (~/arduino-1.6.5/hardware/arduino/avr/cores/arduino/wiring_digital.c). FWIW, my board definition delegates to the standard ".build.core=arduino:arduino", but I thought the whole point of pins_arduino.h was to over-ride pin-function-mappings in this manner. 

So I'm totally puzzled as to what this means. Anyone encounter this before / know what I'm doing wrong? I think I can trivially "fix" this for myself by coming up with a new name to use for my mapping and using it instead of digital_pin_to_PCMSK_bit_PGM in my digitalPinToPCMSKbit macro in pins_arduino.h, but I thought it was strange enough to me to bring to the list for review. I guess I'm concerned about what might be quietly using the mysteriously defined digital_pin_to_PCMSK_bit_PGM array if I sweep it under the rug in that manner.

Insights and feedback appreciated!

Kind Regards,
Vic

Victor Aprea // Wicked Device

William Westfield

unread,
Nov 24, 2015, 12:48:45 PM11/24/15
to devel...@arduino.cc
> #ifndef ARDUINO_MAIN
> extern const uint8_t PROGMEM digital_pin_to_PCMSK_bit_PGM;
> #endif
>
> ... so I removed that block of code and tried to replace it with my own definition of digital_pin_to_PCMSK_bit_PGM. But when I do that and try to compile a basic sketch, I get the following compile time output from the IDE.
>
> /tmp/build4992724107852600463.tmp/core.a(wiring.c.o):(.progmem.data.digital_pin_to_PCMSK_bit_PGM+0x0): multiple definition of `digital_pin_to_PCMSK_bit_PGM’

Did you keep “ARDUINO_MAIN” logic? Otherwise you could get a separate digital_pin_to_PCMSK_bit_PGM in each file that includes pins_arduino.h (I believe that the idea is that ARDUINO_MAIN is defined for only pins_arduino.cpp, and creates the array, while everything else gets an “extern …” definition.)

(although it looks like most of the current PCMSK mapping is done by macros that don’t use the arrays.)

BillW/WestfW

Victor Aprea

unread,
Nov 24, 2015, 12:59:04 PM11/24/15
to Arduino Developers
Oh that was dumb of me, you can't declare an array in a header file without guarding it from redefinition... 

Changing these lines in pins_arduino.h:

#ifndef ARDUINO_MAIN
extern const uint8_t PROGMEM digital_pin_to_PCMSK_bit_PGM;
#endif

to:

#ifndef ARDUINO_MAIN
extern const uint8_t PROGMEM digital_pin_to_PCMSK_bit_PGM[];
#endif 

... i.e. adding the []  seems to have fixed my actual bug.

Regards,
Vic

Victor Aprea // Wicked Device

Reply all
Reply to author
Forward
0 new messages