I can't build libbson from mongo-c-driver 1.20.0 on Mac OS X 10.6.8 with Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn) from Xcode 3.2.6. The error is:
src/libbson/src/bson/bson-context.c:234:4: warning: implicit declaration of function 'arc4random_buf' is invalid in C99 [-Wimplicit-function-declaration] arc4random_buf (&result, sizeof (result)); ^ 1 warning generated.
Undefined symbols for architecture i386: "_arc4random_buf", referenced from: __bson_context_init_random in bson-context.c.o ld: symbol(s) not found for architecture i386
This problem was introduced in https://github.com/mongodb/mongo-c-driver/pull/723 by unconditionally using arc4random_buf on macOS. arc4random_buf was introduced in Mac OS X 10.7.
This made me look at the code in _get_rand which raised a few questions:
- Why is a potentially inaccurate list of arc4random_buf-supporting systems being maintained in this file? Wouldn't it be simpler and better to detect the availability of arc4random_buf at configure time?
- If rand_r is not defined but arc4random_buf is, why does it use rand instead of arc4random_buf? Shouldn't arc4random_buf be the first choice if it is available?
Assuming the answer to both questions is that there is no good reason, I propose the following modification to address these issues:
- is related to
-
CDRIVER-4233 error: implicit declaration of function 'arc4random_buf' is invalid in C99
- Closed