ESP32 C3 link error cmath pow function

when building to a ESP32-C3 I get the following link error by cmath pow function…

/home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/newlib/syscalls.c:147: multiple definition of `fcntl'; c:/users/trasa/.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/lib/rv32imc/ilp32/no-rtti\libc.a(lib_a-sysfcntl.o):/builds/idf/crosstool-NG/.build/HOST-x86_64-w64-mingw32/riscv32-esp-elf/src/newlib/newlib/libc/syscalls/sysfcntl.c:11: first defined here
c:/users/trasa/.platformio/packages/toolchain-riscv32-esp/bin/../lib/gcc/riscv32-esp-elf/8.4.0/../../../../riscv32-esp-elf/bin/ld.exe: .pio/build/airm2m_core_esp32c3/liba53/libAdafruit BME280 Library.a(Adafruit_BME280.cpp.o): in function `__gnu_cxx::__promote_2<float, double, __gnu_cxx::__promote<float, std::__is_integer<float>::__value>::__type, __gnu_cxx::__promote<double, std::__is_integer<double>::__value>::__type>::__type std::pow<float, double>(float, double)':
c:\users\trasa\.platformio\packages\toolchain-riscv32-esp\riscv32-esp-elf\include\c++\8.4.0/cmath:418: undefined reference to `pow'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\airm2m_core_esp32c3\firmware.elf] Error 1

I’m using the Adafruit BME280 library which seems to be using the math ‘pow’ function.

When building to ESP32 ‘xtensa’ with the same code everything works fine but with the ESP32-C3 ‘riscv32’ the math pow function gives undefined reference.

Anyone have an idea on why this is happening?

Using the Arduino IDE with similar code things build fine.

You have to link it with libm.a that contains that symbol. Append your linking flags with -lm option

I have that option in the build_flags section in the platformio.ini file but it makes no difference. Everything works fine when I use the original ESP32, it gives this problem only when I switch to the ESP32-C3. Could it be the riscv-32 toolchain?

Sorry, I’m not familiar with platformio. But you should add this into linking flags (not cflags, compile_flags,…)

Because the order of parameters passed to command line is important here

@fillzee , I hope this could help you Extra linker flags without -Wl, prefix — PlatformIO latest documentation

Ok, after following suggestions and banging my head on my desk for the last 2 weeks I finally resolved the problem. After deleting all the installed platformio packages in “C:\Users\myuser.platformio\packages” and deleting the “.pio” and “.vscode” folders in the workspace folder everything finally built without issues. Platformio/VSCode downloaded and installed the packages again and things worked as should.

1 Like