Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get FMT_COMPILE to compile on ESP32 #2116

Closed
summivox opened this issue Jan 28, 2021 · 5 comments · Fixed by #2117
Closed

Unable to get FMT_COMPILE to compile on ESP32 #2116

summivox opened this issue Jan 28, 2021 · 5 comments · Fixed by #2117

Comments

@summivox
Copy link
Contributor

summivox commented Jan 28, 2021

Platform: https://github.com/espressif/esp-idf

Compiler:

$ xtensa-esp32-elf-g++ --version
xtensa-esp32-elf-g++ (crosstool-NG esp-2020r3) 8.4.0
Copyright (C) 2018 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.

Code:

auto result = fmt::format(FMT_COMPILE("{}"), 12345);

Expected Result:
Code compiles.

Actual Result:
Code does not compile. Error message:

$ cmake
[1/9] Performing build step for 'bootloader'
ninja: no work to do.
[2/7] Building CXX object esp-idf/main/CMakeFiles/__idf_main.dir/app_main.cpp.obj
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/app_main.cpp.obj 
/home/summivox/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++  -DHAVE_CONFIG_H -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -DUNITY_INCLUDE_CONFIG_H -DWITH_POSIX -Iconfig -I../main -I/home/summivox/lib/esp-idf/components/newlib/platform_include -I/home/summivox/lib/esp-idf/components/freertos/include -I/home/summivox/lib/esp-idf/components/freertos/port/xtensa/include -I/home/summivox/lib/esp-idf/components/esp_hw_support/include -I/home/summivox/lib/esp-idf/components/esp_hw_support/port/esp32/. -I/home/summivox/lib/esp-idf/components/heap/include -I/home/summivox/lib/esp-idf/components/log/include -I/home/summivox/lib/esp-idf/components/lwip/include/apps -I/home/summivox/lib/esp-idf/components/lwip/include/apps/sntp -I/home/summivox/lib/esp-idf/components/lwip/lwip/src/include -I/home/summivox/lib/esp-idf/components/lwip/port/esp32/include -I/home/summivox/lib/esp-idf/components/lwip/port/esp32/include/arch -I/home/summivox/lib/esp-idf/components/soc/include -I/home/summivox/lib/esp-idf/components/soc/esp32/. -I/home/summivox/lib/esp-idf/components/soc/esp32/include -I/home/summivox/lib/esp-idf/components/hal/esp32/include -I/home/summivox/lib/esp-idf/components/hal/include -I/home/summivox/lib/esp-idf/components/esp_rom/include -I/home/summivox/lib/esp-idf/components/esp_rom/esp32 -I/home/summivox/lib/esp-idf/components/esp_common/include -I/home/summivox/lib/esp-idf/components/esp_system/include -I/home/summivox/lib/esp-idf/components/esp32/include -I/home/summivox/lib/esp-idf/components/driver/include -I/home/summivox/lib/esp-idf/components/driver/esp32/include -I/home/summivox/lib/esp-idf/components/esp_ringbuf/include -I/home/summivox/lib/esp-idf/components/efuse/include -I/home/summivox/lib/esp-idf/components/efuse/esp32/include -I/home/summivox/lib/esp-idf/components/xtensa/include -I/home/summivox/lib/esp-idf/components/xtensa/esp32/include -I/home/summivox/lib/esp-idf/components/espcoredump/include -I/home/summivox/lib/esp-idf/components/esp_timer/include -I/home/summivox/lib/esp-idf/components/esp_ipc/include -I/home/summivox/lib/esp-idf/components/esp_pm/include -I/home/summivox/lib/esp-idf/components/vfs/include -I/home/summivox/lib/esp-idf/components/esp_wifi/include -I/home/summivox/lib/esp-idf/components/esp_wifi/esp32/include -I/home/summivox/lib/esp-idf/components/esp_event/include -I/home/summivox/lib/esp-idf/components/esp_netif/include -I/home/summivox/lib/esp-idf/components/esp_eth/include -I/home/summivox/lib/esp-idf/components/tcpip_adapter/include -I/home/summivox/lib/esp-idf/components/app_trace/include -I/home/summivox/lib/esp-idf/components/mbedtls/port/include -I/home/summivox/lib/esp-idf/components/mbedtls/mbedtls/include -I/home/summivox/lib/esp-idf/components/mbedtls/esp_crt_bundle/include -I/home/summivox/lib/esp-idf/components/bootloader_support/include -I/home/summivox/lib/esp-idf/components/app_update/include -I/home/summivox/lib/esp-idf/components/spi_flash/include -I/home/summivox/lib/esp-idf/components/nvs_flash/include -I/home/summivox/lib/esp-idf/components/pthread/include -I/home/summivox/lib/esp-idf/components/esp_gdbstub/include -I/home/summivox/lib/esp-idf/components/esp_gdbstub/xtensa -I/home/summivox/lib/esp-idf/components/esp_gdbstub/esp32 -I/home/summivox/lib/esp-idf/components/wpa_supplicant/include -I/home/summivox/lib/esp-idf/components/wpa_supplicant/port/include -I/home/summivox/lib/esp-idf/components/wpa_supplicant/include/esp_supplicant -I/home/summivox/lib/esp-idf/components/perfmon/include -I/home/summivox/lib/esp-idf/components/asio/asio/asio/include -I/home/summivox/lib/esp-idf/components/asio/port/include -I/home/summivox/lib/esp-idf/components/cbor/port/include -I/home/summivox/lib/esp-idf/components/unity/include -I/home/summivox/lib/esp-idf/components/unity/unity/src -I/home/summivox/lib/esp-idf/components/cmock/CMock/src -I/home/summivox/lib/esp-idf/components/coap/port/include -I/home/summivox/lib/esp-idf/components/coap/port/include/coap -I/home/summivox/lib/espummivox/lib/esp-idf/components/coap/libcoap/include/coap2 -I/home/summivox/lib/esp-idf/components/console -I/home/summivox/lib/esp-idf/components/nghttp/port/include -I/home/summivox/lib/esp-idf/components/nghttp/nghttp2/lib/includes -I/home/summivox/lib/esp-idf/components/esp-tls -I/home/summivox/lib/esp-idf/components/esp-tls/esp-tls-crypto -I/home/summivox/lib/esp-idf/components/esp_adc_cal/include -I/home/summivox/lib/esp-idf/components/esp_hid/include -I/home/summivox/lib/esp-idf/components/tcp_transport/include -I/home/summivox/lib/esp-idf/components/esp_http_client/include -I/home/summivox/lib/esp-idf/components/esp_http_server/include -I/home/summivox/lib/esp-idf/components/esp_https_ota/include -I/home/summivox/lib/esp-idf/components/esp_littlefs/src -I/home/summivox/lib/esp-idf/components/esp_littlefs/include -I/home/summivox/lib/esp-idf/components/protobuf-c/protobuf-c -I/home/summivox/lib/esp-idf/components/protocomm/include/common -I/home/summivox/lib/esp-idf/components/protocomm/include/security -I/home/summivox/lib/esp-idf/components/protocomm/include/transports -I/home/summivox/lib/esp-idf/components/mdns/include -I/home/summivox/lib/esp-idf/components/esp_local_ctrl/include -I/home/summivox/lib/esp-idf/components/sdmmc/include -I/home/summivox/lib/esp-idf/components/esp_serial_slave_link/include -I/home/summivox/lib/esp-idf/components/esp_websocket_client/include -I/home/summivox/lib/esp-idf/components/expat/expat/expat/lib -I/home/summivox/lib/esp-idf/components/expat/port/include -I/home/summivox/lib/esp-idf/components/wear_levelling/include -I/home/summivox/lib/esp-idf/components/fatfs/diskio -I/home/summivox/lib/esp-idf/components/fatfs/vfs -I/home/summivox/lib/esp-idf/components/fatfs/src -I/home/summivox/lib/esp-idf/components/freemodbus/common/include -I/home/summivox/lib/esp-idf/components/idf_test/include -I/home/summivox/lib/esp-idf/components/idf_test/include/esp32 -I/home/summivox/lib/esp-idf/components/jsmn/include -I/home/summivox/lib/esp-idf/components/json/cJSON -I/home/summivox/lib/esp-idf/components/libsodium/libsodium/src/libsodium/include -I/home/summivox/lib/esp-idf/components/libsodium/port_include -I/home/summivox/lib/esp-idf/components/mqtt/esp-mqtt/include -I/home/summivox/lib/esp-idf/components/openssl/include -I/home/summivox/lib/esp-idf/components/spiffs/include -I/home/summivox/lib/esp-idf/components/ulp/include -I/home/summivox/lib/esp-idf/components/wifi_provisioning/include -I../components/fmtlib/fmt/include -I../components/minmea/minmea -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -O2 -std=gnu++11 -fno-exceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.3-dev-2398-g2bfdd036b-dirty\" -DESP_PLATFORM -std=gnu++2a -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/app_main.cpp.obj -MF esp-idf/main/CMakeFiles/__idf_main.dir/app_main.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/app_main.cpp.obj -c ../main/app_main.cpp
In file included from ../main/app_main.cpp:10:
../components/fmtlib/fmt/include/fmt/compile.h: In instantiation of 'constexpr auto fmt::v7::detail::compile_format_string(S) [with Args = fmt::v7::detail::type_list<int>; unsigned int POS = 0; int ID = 0; S = MainTask(void*)::<lambda()>::FMT_COMPILE_STRING]':
../components/fmtlib/fmt/include/fmt/compile.h:598:72:   required from 'constexpr auto fmt::v7::detail::compile(S) [with Args = {int}; S = MainTask(void*)::<lambda()>::FMT_COMPILE_STRING; typename std::enable_if<(fmt::v7::is_compile_string<S>::value || fmt::v7::detail::is_compiled_string<S>::value), int>::type <anonymous> = 0]'
../components/fmtlib/fmt/include/fmt/compile.h:677:53:   required from 'std::__cxx11::basic_string<typename S::char_type> fmt::v7::format(const S&, Args&& ...) [with S = MainTask(void*)::<lambda()>::FMT_COMPILE_STRING; Args = {int}; typename std::enable_if<fmt::v7::detail::is_compiled_string<S>::value, int>::type <anonymous> = 0; typename S::char_type = char; typename Context::char_type = char]'
../main/app_main.cpp:63:48:   required from here
../components/fmtlib/fmt/include/fmt/compile.h:558:58: error: exception handling disabled, use -fexceptions to enable
       throw format_error("unmatched '{' in format string");
                                                          ^
ninja: build stopped: subcommand failed.
The terminal process terminated with exit code: 1.

Workaround:

auto result = fmt::format(fmt::compile("{}"), 12345);

This does compile, but complains about fmt::compile being deprecated.

Investigation:
Here:

constexpr auto compile_format_string(S format_str) {

Even though I had no prior experience with debugging constexpr stuff in compile time, after inserting some "if (...) throw ...", I found out that format_str.size() == 1 which does not make sense.

@summivox
Copy link
Contributor Author

Update: fmt::compile failed at runtime, with similar error.
I think the root cause might lie within how the string literal is massaged.


0x40086b3e: panic_abort at /home/summivox/lib/esp-idf/components/esp_system/panic.c:367

0x4008711d: esp_system_abort at /home/summivox/lib/esp-idf/components/esp_system/system_api.c:108

0x4008c8a6: abort at /home/summivox/lib/esp-idf/components/newlib/abort.c:46

0x400f8ab7: __cxxabiv1::__terminate(void (*)()) at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:47

0x400f8afe: std::terminate() at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:57

0x400e5bb3: fmt::v7::detail::assert_fail(char const*, int, char const*) at /home/summivox/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.4.0/bits/basic_string.h:200

0x400e6974: fmt::v7::detail::error_handler::on_error(char const*) at /home/summivox/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/xtensa-esp32-elf/include/c++/8.4.0/bits/basic_string.h:200

0x400dbdf7: void fmt::v7::detail::compile_format_string<false, char, fmt::v7::detail::compiled_format_base<char const*, void>::compiled_format_base(fmt::v7::basic_string_view<char>)::{lambda(fmt::v7::detail::format_part<char> const&)#1}>(fmt::v7::basic_string_view<char>, fmt::v7::detail::compiled_format_base<char const*, void>::compiled_format_base(fmt::v7::basic_string_view<char>)::{lambda(fmt::v7::detail::format_part<char> const&)#1}) at /media/summivox/nautilus-data/proj/shift-watch-esp32/build/../components/fmtlib/fmt/include/fmt/compile.h:202
 (inlined by) ?? at /media/summivox/nautilus-data/proj/shift-watch-esp32/build/../components/fmtlib/fmt/include/fmt/format.h:3097
 (inlined by) ?? at /media/summivox/nautilus-data/proj/shift-watch-esp32/build/../components/fmtlib/fmt/include/fmt/format.h:3153
 (inlined by) void fmt::v7::detail::compile_format_string<false, char, fmt::v7::detail::compiled_format_base<char const*, void>::compiled_format_base(fmt::v7::basic_string_view<char>)::{lambda(fmt::v7::detail::format_part<char> const&)#1}>(fmt::v7::basic_string_view<char>, fmt::v7::detail::compiled_format_base<char const*, void>::compiled_format_base(fmt::v7::basic_string_view<char>)::{lambda(fmt::v7::detail::format_part<char> const&)#1}) at /media/summivox/nautilus-data/proj/shift-watch-esp32/build/../components/fmtlib/fmt/include/fmt/compile.h:217

@vitaut
Copy link
Contributor

vitaut commented Jan 28, 2021

I'm not sure about this particular compiler but here's an example with gcc 8 it seems to be based on: https://godbolt.org/z/v1qvs8.

fmt::compile is deprecated and will be removed.

@vitaut
Copy link
Contributor

vitaut commented Jan 28, 2021

From the error message it looks like you should compile with exceptions enabled.

@vitaut vitaut closed this as completed Jan 28, 2021
vitaut pushed a commit that referenced this issue Jan 28, 2021
@eos175
Copy link

eos175 commented Mar 25, 2021

Hello, how can i compile with esp-idf on esp32?

try adding fmtlib to components folder, thank!!

@vitaut
Copy link
Contributor

vitaut commented Mar 25, 2021

Hello, how can i compile with esp-idf on esp32?

Unfortunately I am not familiar with these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants