Repository navigation
MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE) #283
Description
The MSVC-Build is currently (develop: d9738c3) broken. It looks like a 4-year-old regression (see below).
Observation
Building with basic cmake commands under Win11 with VS2026:
$ rm -rf build/; cmake -B build && cmake --build build
-- Building for: Visual Studio 18 2026
-- Selecting Windows SDK version 10.0.26100.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.51.36256.0
-- The CXX compiler identification is MSVC 19.51.36256.0
[...]
D:\github\eclipse-tinydtls\tinydtls\dtls_debug.c(402,16): error C2065: 'DTLS_DEBUG_BUF_SIZE': undeclared identifier [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]
D:\github\eclipse-tinydtls\tinydtls\dtls_debug.c(402,16): error C2057: expected constant expression [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]
D:\github\eclipse-tinydtls\tinydtls\dtls_debug.c(402,16): error C2466: cannot allocate an array of constant size 0 [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]
D:\github\eclipse-tinydtls\tinydtls\dtls_debug.c(402,8): error C2133: 'message': unknown size [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]Build fails because of error C2065: 'DTLS_DEBUG_BUF_SIZE': undeclared identifier.
Analysis
The indentifier DTLS_DEBUG_BUF_SIZE is undeclared in this constellation because
-
It gets declared inside a preprocessor condition
#if !defined(WITH_CONTIKI) && !defined(_MSC_VER):
Lines 250 to 279 in d9738c3
#if !defined(WITH_CONTIKI) && !defined(_MSC_VER) static void dtls_logging_handler(log_t level, const char *message) { static char timebuf[32]; FILE* log_fd = level <= DTLS_LOG_CRIT ? stderr : stdout; if (print_timestamp(timebuf,sizeof(timebuf), time(NULL))) fprintf(log_fd, "%s ", timebuf); if (level <= DTLS_LOG_DEBUG) fprintf(log_fd, "%s ", loglevels[level]); fwrite(message, strlen(message), 1, log_fd); fflush(log_fd); } static dtls_log_handler_t log_handler = dtls_logging_handler; void dtls_set_log_handler(dtls_log_handler_t app_handler) { if (app_handler == NULL) log_handler = dtls_logging_handler; else log_handler = app_handler; } #ifndef DTLS_DEBUG_BUF_SIZE #define DTLS_DEBUG_BUF_SIZE 128 #endif -
It gets used inside a different preprocessor condition
#ifndef WITH_CONTIKI
Lines 397 to 403 in d9738c3
#ifndef WITH_CONTIKI void dtls_dsrv_hexdump_log(log_t level, const char *name, const unsigned char *buf, size_t length, int extend) { int n = 0; #ifndef DTLS_CONSTRAINED_STACK char message[DTLS_DEBUG_BUF_SIZE]; #endif /* ! DTLS_CONSTRAINED_STACK */
This means that the identifier is undeclared when building without contiki with the MSVC compiler.
It has probably been this way since the introduction of DTLS_DEBUG_BUF_SIZE in 2022: 70a2b39 (unconfirmed).
Conclusion
I'm not sure what the correct fix would be, but changing the latter condition to equal the former at least builds without errors again.
Activity
[-]MSVC-Build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/-][+]MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/+]d5UtQvp8QQU9 commentedon Sep 4, 2026
Only true for static libs. With
-DBUILD_SHARED_LIBS=ONit becomes obvious that a MSVC-compatible implementation ofdtls_dsrv_hexdump_log()is missing from the sources:[-]MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/-][+]MSVC build is broken (undeclared `DTLS_DEBUG_BUF_SIZE`)[/+]boaks commentedon Sep 4, 2026
AFAIK, there some more issues/pain points using tinydtls with MSVC.
At least my part of the work for this project is my free time (hobby), sharing that time with Eclipse/Californium and my Zephyr/CoAP modem client. In the end it's not possible for me to cover MSVC as well.
Maybe others do that.
d5UtQvp8QQU9 commentedon Sep 7, 2026
Ok, thanks.
Would you accept contributions or is MSVC out of scope for your repo?
Would providing a PR that fixes current issues suffice or are you looking for someone with long-term commitment?
I leave it up to you to decide whether to close this issue.
boaks commentedon Sep 7, 2026
I accept contributions, but we may need someone to review it ...
mrdeep1 commentedon Oct 3, 2026
Please checkout #301 and confirm if this fixed your issue.