[CDRIVER-4609] implicit declaration of function 'aligned_alloc' Created: 09/Apr/23  Updated: 27/Oct/23  Resolved: 11/Apr/23

Status: Closed
Project: C Driver
Component/s: BSON
Affects Version/s: 1.23.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Ryan Schmidt Assignee: Ezra Chung
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File log.txt    
Issue Links:
Related
is related to CDRIVER-4580 Document dropping support of macOS 10... Closed

 Description   

Summary

src/libbson/src/bson/bson-memory.c:38:11: error: implicit declaration of function 'aligned_alloc' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
   return aligned_alloc (alignment, num_bytes);
          ^
src/libbson/src/bson/bson-memory.c:38:11: error: incompatible integer to pointer conversion returning 'int' from a function with result type 'void *' [-Werror,-Wint-conversion]
   return aligned_alloc (alignment, num_bytes);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.

Environment

mongo-c-driver 1.23.3

macOS 10.14.x x86_64

Apple LLVM version 10.0.1 (clang-1001.0.46.4)

How to Reproduce

Build mongo-c-driver on macOS 10.14.x with clang from Xcode 10.3

Additional Background

It builds fine with macOS 10.15.x and Xcode 11.7 and later macOS/Xcode combinations, but not on macOS 10.14.x and Xcode 10.3 and earlier macOS/Xcode combinations. 



 Comments   
Comment by Ezra Chung [ 11/Apr/23 ]

Hello, ryandesign. Thank you for submitting this report.

We are planning to drop support for MacOS 10.14 as documented in CDRIVER-4580 (edit: corrected). Given this issue is exclusive to 10.14 and older, we will elect to close this ticket to avoid introducing workarounds for (to be) unsupported platforms.

That being said, in addition to the patch you have already applied, you also may want to consider exploring the solutions documented in Homebrew PR #45585 (referenced by Issue #46393) to see if it is applicable to your situation:

We've discovered that the 11.0 CLT (11.1 CLT does not exist), which the CI uses, shipped with the wrong system headers in the 10.14 SDK: #46466 (comment). The problem has been fixed in 11.2. Apparently a lot of people don't have the 11.0 CLT because Apple also botched up the update process, henced why this fix worked locally for some - they weren't using the broken CLT.

Comment by Ryan Schmidt [ 09/Apr/23 ]

Rather than building up ever more complex ifdefs, you may prefer to detect the availability of aligned_alloc in your cmake script.

Comment by Ryan Schmidt [ 09/Apr/23 ]

The compiler version doesn't seem to be relevant. I still see this problem when using a newer compiler on an older OS. It seems that the version of libc++ included in macOS 10.14.x and earlier doesn't have aligned_alloc.

You already have alternative implementations that you use on other systems (such as on Windows, according to CDRIVER-4550) so it should be possible to do the same for older macOS versions.

This patch works for me and allows it to build on Mac OS X 10.6 and later (I didn't test earlier versions): https://github.com/macports/macports-ports/blob/558d2ca208365d40cfc9b3b36d1dd9c175fb9a7b/devel/mongo-c-driver/files/aligned_alloc.patch

Generated at Wed Feb 07 21:21:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.