'Swift Package with C++ builds in Xcode but not on CLI

I have a Swift package that includes C++ and ObjC code.

It builds & runs with no issues in the Xcode 13.3 IDE and when building it as part of an app using xcodebuild on CLI, but when I try to build it on the command-line with swift build it fails with several errors (these are representative errors; there are many more):

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:523:1: error: expected unqualified-id
@class NSString, Protocol;
^

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:525:9: error: unknown type name 'NSString'
typedef NSString * NSExceptionName NS_TYPED_EXTENSIBLE_ENUM;
        ^

It looks like the compiler is trying to compile ObjC headers as C++, but I'm not quite certain what is happening.

Is there something more I must do (command-line options, Package.swift additions, etc.) to make my package compile & run using swift build?

Here is a link to the package if you want to look at source or try it yourself: https://github.com/TralaEngineering/verovio



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source