[CDRIVER-4233] error: implicit declaration of function 'arc4random_buf' is invalid in C99 Created: 25/Nov/21 Updated: 28/Oct/23 Resolved: 13/Dec/21 |
|
| Status: | Closed |
| Project: | C Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 1.20.1 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Ryan Schmidt | Assignee: | Kevin Albertson |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
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:
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. |
| Comments |
| Comment by Githook User [ 13/Dec/21 ] |
|
Author: {'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}Message: |
| Comment by Githook User [ 13/Dec/21 ] |
|
Author: {'name': 'Kevin Albertson', 'email': 'kevin.albertson@mongodb.com', 'username': 'kevinAlbs'}Message: |
| Comment by Kevin Albertson [ 11/Dec/21 ] |
|
Thank you for the report ryandesign. I am able to reproduce this on my macOS 11.6.1 with Apple clang version 13.0.0 (clang-1300.0.29.3). I believe this is a regression introduced in 1.20.0 as part of
cdefs.h on macOS defines _POSIX_C_SOURCE 200809L if -D_XOPEN_SOURCE=700 is present. _POSIX_C_SOURCE 200809L causes arc4random to be removed from stdlib.h here. POSIX_C_SOURCE 200809L causes __DARWIN_C_LEVEL to be defined as POSIX_C_SOURCE in cdefs.h here. libbson's CHECK_SYMBOL_EXISTS for strlcpy do not apply -D_XOPEN_SOURCE=700. cmake defines BSON_HAVE_STRLCPY thinking that strlcpy is defined, but compilation fails. |