Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-4233

error: implicit declaration of function 'arc4random_buf' is invalid in C99

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.20.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I can't build libbson from mongo-c-driver 1.20.0 on macOS Catalina 10.15.7 with Apple clang version 12.0.0 (clang-1200.0.32.29) from Xcode 12.4. The error is:

      src/libbson/src/bson/bson-context.c:234:4: error: implicit declaration of function 'arc4random_buf' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
       arc4random_buf (&result, sizeof (result));
       ^
       1 error generated.
      src/libbson/src/bson/bson-string.c:554:4: error: implicitly declaring library function 'strlcpy' with type 'unsigned long (char *, const char *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
       strlcpy (dst, src, size);
       ^
      src/libbson/src/bson/bson-string.c:554:4: note: include the header <string.h> or explicitly provide a declaration for 'strlcpy'
      1 error generated.

      arc4random_buf is only defined in stdlib.h if !defined(_ANSI_SOURCE) && (!defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)).

      Defining _DARWIN_C_SOURCE works around the problem but I don't know if that's the best solution.

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            ryandesign Ryan Schmidt
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: