Linker error when using unordered_map

Benjii

New member
Board: Teensy 3.6
Toolchain-version: teensy-compile/15.2.1

Sketch to reproduce:
C++:
using namespace std;

unordered_map<int, int> floormap_stepper = {{1, 1}};

void setup() {}

void loop() {}

When using an unordered_map, the Linker does not find a floor() reference:
Code:
Linking everything together...
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/arm-none-eabi-gcc -O2 -Wl,--gc-sections,--relax,--no-warn-rwx-segments,--defsym=__rtc_localtime=1784903286 -T/home/benji/.arduino15/packages/teensy/hardware/avr/1.62.0/cores/teensy3/mk66fx1m0.ld -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -o /home/benji/.cache/arduino/sketches/9F9B2C8D6A15A62AB1000E144EF731B7/sketch_jul24a.ino.elf /home/benji/.cache/arduino/sketches/9F9B2C8D6A15A62AB1000E144EF731B7/sketch/sketch_jul24a.ino.cpp.o /home/benji/.cache/arduino/sketches/9F9B2C8D6A15A62AB1000E144EF731B7/core/core.a -L/home/benji/.cache/arduino/sketches/9F9B2C8D6A15A62AB1000E144EF731B7 -larm_cortexM4lf_math -lm -lstdc++
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o): in function `std::__detail::_Prime_rehash_policy::_M_next_bkt(unsigned int) const':
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0x68): undefined reference to `floor'
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: (floor): Unknown destination type (ARM/Thumb) in /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0x68): dangerous relocation: unsupported relocation
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0xa2): undefined reference to `floor'
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: (floor): Unknown destination type (ARM/Thumb) in /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0xa2): dangerous relocation: unsupported relocation
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o): in function `std::__detail::_Prime_rehash_policy::_M_need_rehash(unsigned int, unsigned int, unsigned int) const':
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x60): undefined reference to `floor'
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: (floor): Unknown destination type (ARM/Thumb) in /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x60): dangerous relocation: unsupported relocation
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x96): undefined reference to `floor'
/home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/bin/ld: (floor): Unknown destination type (ARM/Thumb) in /home/benji/.arduino15/packages/teensy/tools/teensy-compile/15.2.1/arm/bin/../lib/gcc/arm-none-eabi/15.2.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x96): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status
exit status 1

I don't have much experience with the inner workings of the c++ compiler/linker toolchain so I had Claude walk me through it and it ended up suggesting me this working way to resolve this:

in "~/.arduino15/packages/teensy/hardware/avr/1.62.0/boards.txt"
find "teensy36.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++"
change it to "teensy36.build.flags.libs=-larm_cortexM4lf_math -Wl,--start-group -lm -lstdc++ -Wl,--end-group"

So that ld rescans them until everything resolves as (if I get it right) unordered_maps dependancy of floor() is realized at the -lstdc step but floor() would be found at the -lm step, but as the -lm step is already done, the linker does not revisit it to resolve the floor() dependancy.
With the two arguments grouped, the linker can revisit them which resolves this.

I don't know if this way to resolve this imposes other things not wanted by Teensyduino, I just wanted to resolve this issue for me and help the ones looking for this after me.

I hope that this gets fixed in the next toolchain-version as it would overwrite this change made in the boards.txt.

Feel free point me to relevant other issues if this is a duplicate of anything :D
 
@PaulStoffregen or other might investigate or clarify if that is a safe update/proper to make to the Teensy boards.txt.

Just a suggestion to try: Move that EDIT into boards.local.txt (and restore the original command) and restart the IDE and see if it picks it up as a replacement command for the line. That .local. file with still need to be copied back in with each update to the TeensyDuino build - but would not require editing the PJRC source.
 
Code:
ld.exe: C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o): in function std::__detail::_Prime_rehash_policy::_M_next_bkt(unsigned int) const
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0x68): undefined reference to floor
ld.exe: (floor): Unknown destination type (ARM\Thumb) in C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0x68): dangerous relocation: unsupported relocation
ld.exe: hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0xa2): undefined reference to floor
ld.exe: (floor): Unknown destination type (ARM\Thumb) in C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy11_M_next_bktEj+0xa2): dangerous relocation: unsupported relocation
ld.exe: C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o): in function std::__detail::_Prime_rehash_policy::_M_need_rehash(unsigned int, unsigned int, unsigned int) const
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x60): undefined reference to floor
ld.exe: (floor): Unknown destination type (ARM\Thumb) in C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x60): dangerous relocation: unsupported relocation
ld.exe: hashtable_c++0x.cc:(.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x96): undefined reference to floor
ld.exe: (floor): Unknown destination type (ARM\Thumb) in C:\Program Files (x86)\Arduino\hardware\tools\arm\bin\..\lib\gcc\arm-none-eabi\15.2.1\..\..\..\..\arm-none-eabi\lib\thumb\v7e-m+fp\hard\libstdc++.a(hashtable_c++0x.o)
hashtable_c++0x.cc*: (.text._ZNKSt8__detail20_Prime_rehash_policy14_M_need_rehashEjjj+0x96): dangerous relocation: unsupported relocation
collect2.exe*: error: ld returned 1 exit status
 

Error linking for board Teensy 3.6 (teensy36)
Using Arduino 1.8.19 still gives errors as shown above. This is with the latest TeensyDuino.
 
@PaulStoffregen or other might investigate or clarify if that is a safe update/proper to make to the Teensy boards.txt.

Just a suggestion to try: Move that EDIT into boards.local.txt (and restore the original command) and restart the IDE and see if it picks it up as a replacement command for the line. That .local. file with still need to be copied back in with each update to the TeensyDuino build - but would not require editing the PJRC source.
This works like you said, thank you for the suggestion (y)
 
Back
Top