enzo1982 / BoCA

A component library used by the fre:ac audio converter
https://www.freac.org/
GNU General Public License v2.0
36 stars 9 forks source link

Fix build on 10.6.x for ppc #13

Closed barracuda156 closed 1 year ago

barracuda156 commented 1 year ago

Fixes: https://github.com/enzo1982/BoCA/issues/12

enzo1982 commented 1 year ago

I think this not the correct way to fix this.

The MacOS X 10.6 SDK defines the kAudioFormatMPEG4AAC_ELD constant, see here. So if it is not defined in your build, you must be using earlier headers (probably from the MacOS X 10.5 SDK). However, when using earlier headers, you should not set the target OS version to 10.6 which causes MAC_OS_X_VERSION_10_6 to be defined.

Ideally, set the target to 10.5 in your build and this should not be an issue. Setting the MACOSX_DEPLOYMENT_TARGET environment variable to 10.5 may already be enough to fix this.

The other option would be to make sure you actually build using the 10.6 SDK which defines kAudioFormatMPEG4AAC_ELD. I would not recommend this, though, as this could easily produce binaries that won't run on 10.5 due to dependencies on 10.6 features.

barracuda156 commented 1 year ago

First of all, there are two cases of 10.6/ppc: native developer build 10A190 (last one known to run on PPC) and Rosetta from 10.6.x releases. 10A190 does use earlier headers, which is nevertheless 10.6 version, not 10.5. However, the same symbol error is observed on 10.6.8 Rosetta, which has standard headers. Maybe something makes it defined only for Intel, despite a mention in that CoreAudio file?

Using older SDK is a hack: I think it is a fallback when nothing works and results in suboptimal build, but here a native one works fine with a one line tweak. If there is any concern of a conflict, maybe define it when it is otherwise undefined?

enzo1982 commented 1 year ago

So I tried this in a MacOS X 10.6 VM and figured out what happens:

The 10.6 SDK that comes with Xcode 3.2.6 indeed contains a CoreAudioTypes.h that does not define the kAudioFormatMPEG4AAC_ELD constant. Yet the COREAUDIOTYPES_VERSION macro value is 1051 just like in the version I linked above which does define that constant.

The 10.6 SDK that comes with Xcode 4.2 has the kAudioFormatMPEG4AAC_ELD constant, so it was added at some point between Xcode 3.2.6 and 4.2, but without incrementing the value of COREAUDIOTYPES_VERSION.

Because the COREAUDIOTYPES_VERSION macro is the same, there is no way to check whether the constant is defined (it's an enum value, so it cannot be checked with #ifdef).

Checking whether we are building for PPC like in this PR is not an option either. The issue applies to any architecture when using Xcode 3.2.6.

The only idea I have right now for solving this is using a different name for that constant.

However, using the 10.5 SDK as suggested before avoids the issue. This can be achieved by adding the -isysroot option to CXXFLAGS, but maybe MacPorts has a simpler way to specify the build SDK. In any case, adding -isysroot /Developer/SDKs/MacOSX10.5.sdk fixes the issue for me.

barracuda156 commented 1 year ago

@enzo1982 I see, thank you for investigating. Then perhaps worth fixing this even more so? While ppc on 10.6.x is a rather exotic case, Xcode 3.2.6 on 10.6.x is standard, and AFAIU far more common than 4.2 (which was a paid version).

enzo1982 commented 1 year ago

Yes, I will change the names of the three constants to be able to use them independent of the MacOS X SDK. That should fix the issue.

enzo1982 commented 1 year ago

Pushed commit 4ea79d5 to fix this.

barracuda156 commented 1 year ago

Pushed commit 4ea79d5 to fix this.

Fixed with that, closing. Thank you!

enzo1982 commented 1 year ago

Fixed with that, closing. Thank you!

Thank you for being so persistent on this! Wouldn't have figured out the actual cause of the issue otherwise.