elcritch / nesper

Program the ESP32 with Nim! Wrappers around ESP-IDF API's.
Apache License 2.0
202 stars 17 forks source link

error: size of array 'NIM_STATIC_ASSERT_AUX' is negative #9

Closed Psirus closed 3 years ago

Psirus commented 3 years ago

Hi, I'm trying to build the example, and I've actually gotten quite far, 807 out of 812 steps in ninja :). However, there is an error now:

[807/821] Building C object 'esp-idf/main/CMakeFiles/__idf_main.dir/nimcache/@mesp32_nim_test.nim.c.obj'
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/nimcache/@mesp32_nim_test.nim.c.obj 
/home/psirus/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc -DMBEDTLS_CONFIG_FILE=\"mbedtls/esp_config.h\" -Iconfig -I/home/psirus/Code/C/esp-idf/components/newlib/platform_include -I/home/psirus/Code/C/esp-idf/components/freertos/include -I/home/psirus/Code/C/esp-idf/components/heap/include -I/home/psirus/Code/C/esp-idf/components/log/include -I/home/psirus/Code/C/esp-idf/components/soc/esp32/include -I/home/psirus/Code/C/esp-idf/components/soc/include -I/home/psirus/Code/C/esp-idf/components/esp_rom/include -I/home/psirus/Code/C/esp-idf/components/esp_common/include -I/home/psirus/Code/C/esp-idf/components/xtensa/include -I/home/psirus/Code/C/esp-idf/components/xtensa/esp32/include -I/home/psirus/Code/C/esp-idf/components/esp32/include -I/home/psirus/Code/C/esp-idf/components/driver/include -I/home/psirus/Code/C/esp-idf/components/esp_ringbuf/include -I/home/psirus/Code/C/esp-idf/components/esp_event/include -I/home/psirus/Code/C/esp-idf/components/tcpip_adapter/include -I/home/psirus/Code/C/esp-idf/components/lwip/include/apps -I/home/psirus/Code/C/esp-idf/components/lwip/include/apps/sntp -I/home/psirus/Code/C/esp-idf/components/lwip/lwip/src/include -I/home/psirus/Code/C/esp-idf/components/lwip/port/esp32/include -I/home/psirus/Code/C/esp-idf/components/lwip/port/esp32/include/arch -I/home/psirus/Code/C/esp-idf/components/lwip/port/esp32/tcp_isn -I/home/psirus/Code/C/esp-idf/components/vfs/include -I/home/psirus/Code/C/esp-idf/components/esp_wifi/include -I/home/psirus/Code/C/esp-idf/components/esp_wifi/esp32/include -I/home/psirus/Code/C/esp-idf/components/esp_eth/include -I/home/psirus/Code/C/esp-idf/components/efuse/include -I/home/psirus/Code/C/esp-idf/components/efuse/esp32/include -I/home/psirus/Code/C/esp-idf/components/app_trace/include -I/home/psirus/Code/C/esp-idf/components/nvs_flash/include -I/home/psirus/Code/C/esp-idf/components/spi_flash/include -I/home/psirus/Code/C/esp-idf/components/mbedtls/port/include -I/home/psirus/Code/C/esp-idf/components/mbedtls/mbedtls/include -I/home/psirus/Code/C/esp-idf/components/app_update/include -I/home/psirus/Code/C/esp-idf/components/bootloader_support/include -mlongcalls -Wno-frame-address   -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -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 -Og -std=gnu99 -Wno-old-style-declaration -Wno-unused-label -Wno-discarded-qualifiers -Wno-ignored-qualifiers -Wno-error=unused-label -Wno-error=parentheses -Wno-error=implicit-function-declaration -Wno-error=maybe-uninitialized -Wno-error=nonnull -Wno-error=address -Wno-unused-but-set-variable -D_GNU_SOURCE -DIDF_VER=\"v4.0.2-442-g41efdb0b3\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -MD -MT 'esp-idf/main/CMakeFiles/__idf_main.dir/nimcache/@mesp32_nim_test.nim.c.obj' -MF esp-idf/main/CMakeFiles/__idf_main.dir/nimcache/@mesp32_nim_test.nim.c.obj.d -o 'esp-idf/main/CMakeFiles/__idf_main.dir/nimcache/@mesp32_nim_test.nim.c.obj'   -c '../main/nimcache/@mesp32_nim_test.nim.c'
In file included from ../main/nimcache/@mesp32_nim_test.nim.c:8:
../main/nimcache/nimbase.h:275:47: error: size of array 'NIM_STATIC_ASSERT_AUX' is negative
 #define NIM_STATIC_ASSERT(x, msg) typedef int NIM_STATIC_ASSERT_AUX[(x) ? 1 : -1];
                                               ^~~~~~~~~~~~~~~~~~~~~
../main/nimcache/nimbase.h:542:1: note: in expansion of macro 'NIM_STATIC_ASSERT'
 NIM_STATIC_ASSERT(sizeof(NI) == sizeof(void*) && NIM_INTBITS == sizeof(NI)*8, "");
 ^~~~~~~~~~~~~~~~~

The same error appears for "stdlib_io.nim.c.obj" and "stdlib_system.nim.c.obj". For the latter, it also says

../main/nimcache/stdlib_system.nim.c:11:10: fatal error: sys/mman.h: No such file or directory
 #include <sys/mman.h>
          ^~~~~~~~~~~~

Any help would be appreciated. Thanks for this project BTW!

Edit: So it seems nim writes #define NIM_INTBITS 64 into the start of the generated C code. And as far as I understand it, there should be a 32 there. Maybe it doesn't pick up the --cpu:esp option for some reason? It is in main/nim.cfg.

elcritch commented 3 years ago

Did you resolve this? It seems like a configuration issue.

What version of Nim are you using and are you using the nimble esp_build commands? I've been using Nim version 1.4.4.

Psirus commented 3 years ago

No, unfortunately I was not able to resolve this. I am using 1.4.4, but also tried 1.4.0. Didn't try an earlier version since it said 1.4+ in the README. I am using nimble esp_build. The only thing I forgot to mention was is that I had to change the line

bin           = @["esp32_nim_test"]

to

bin           = @["src/esp32_nim_test"]

in the nimble file, because otherwise it would error with Error: cannot open 'esp32_nim_test.nim'. The complete nimble file:

# Package

version       = "0.1.0"
author        = "Psirus"
description   = "A new awesome nimble package"
license       = "MIT"
srcDir        = "src"
bin           = @["src/esp32_nim_test"]

# Dependencies

requires "nim >= 1.4.0"
requires "nesper >= 0.6.0"

include nesper/build_utils/tasks
elcritch commented 3 years ago

I was able to replicate the error. I think the master branch generated a nimble file with a bin = @["esp32_nim_test"] which was a setup I tried earlier but it messes up the build process.

Either way, try updating your Nesper library (v0.6.1 is the new latest on master and devel).

Then remove the bin line in your nimble file, like:

# Package

version       = "0.1.0"
author        = "Psirus"
description   = "A new awesome nimble package"
license       = "MIT"
srcDir        = "src"

# Dependencies

requires "nim >= 1.4.0"
requires "nesper >= 0.6.1"

include nesper/build_utils/tasks

Hopefully that should resolve the build issue!

Psirus commented 3 years ago

That did the trick! Thank you so much.