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

  1. changed the title [-]MSVC-Build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/-] [+]MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/+] on Sep 4, 2026
  2. d5UtQvp8QQU9 commented on Sep 4, 2026

    @d5UtQvp8QQU9
    Author

    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.

    Only true for static libs. With -DBUILD_SHARED_LIBS=ON it becomes obvious that a MSVC-compatible implementation of dtls_dsrv_hexdump_log() is missing from the sources:

    dtls_debug.obj : error LNK2019: unresolved external symbol clock_time referenced in function dtls_dsrv_hexdump_log [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]
    D:\github\eclipse-tinydtls\tinydtls\build\Debug\tinydtls.dll : fatal error LNK1120: 1 unresolved externals [D:\github\eclipse-tinydtls\tinydtls\build\tinydtls.vcxproj]
    
  3. changed the title [-]MSVC build is broken (undeclared DTLS_DEBUG_BUF_SIZE)[/-] [+]MSVC build is broken (undeclared `DTLS_DEBUG_BUF_SIZE`)[/+] on Sep 4, 2026
  4. boaks commented on Sep 4, 2026

    @boaks
    Contributor

    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.

  5. d5UtQvp8QQU9 commented on Sep 7, 2026

    @d5UtQvp8QQU9
    Author

    Ok, thanks.

    Maybe others do that.

    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.

  6. boaks commented on Sep 7, 2026

    @boaks
    Contributor

    I accept contributions, but we may need someone to review it ...

  7. mrdeep1 commented on Oct 3, 2026

    @mrdeep1
    Contributor

    Please checkout #296 and confirm if this fixed your issue.

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