Skip to content

Comments

Fix macOS build: use #if instead of #ifdef for TARGET_OS checks#9

Open
timredfern wants to merge 1 commit intokylemcdonald:masterfrom
timredfern:fix-macos-target-check
Open

Fix macOS build: use #if instead of #ifdef for TARGET_OS checks#9
timredfern wants to merge 1 commit intokylemcdonald:masterfrom
timredfern:fix-macos-target-check

Conversation

@timredfern
Copy link

Problem

Building on macOS fails with:

fatal error: 'MobileCoreServices/MobileCoreServices.h' file not found

Cause

The preprocessor checks in audiodecodercoreaudio.h use #ifdef TARGET_OS_IPHONE and #elif defined TARGET_OS_MAC. However, these macros are defined as 0 or 1 in Apple's TargetConditionals.h, not just defined/undefined.

On macOS, TARGET_OS_IPHONE is defined as 0, so #ifdef TARGET_OS_IPHONE evaluates to true (because the macro exists), causing the iOS header to be included instead of the macOS one.

Fix

Change #ifdef to #if so the value is checked rather than just existence:

#if TARGET_OS_IPHONE
#include <MobileCoreServices/MobileCoreServices.h>
#elif TARGET_OS_MAC
#include <CoreServices/CoreServices.h>
#endif

Tested on macOS 15 with openFrameworks 0.12.1.

TARGET_OS_IPHONE and TARGET_OS_MAC are defined as 0 or 1, not just
defined/undefined. Using #ifdef causes the wrong branch to be taken
on macOS since TARGET_OS_IPHONE is defined (as 0).

This fixes the "MobileCoreServices/MobileCoreServices.h not found"
error when building on macOS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant