Skip to content

MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE) #283

Description

@d5UtQvp8QQU9

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

  1. It gets declared inside a preprocessor condition #if !defined(WITH_CONTIKI) && !defined(_MSC_VER):

    tinydtls/dtls_debug.c

    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

  2. It gets used inside a different preprocessor condition #ifndef WITH_CONTIKI

    tinydtls/dtls_debug.c

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions