niklassaers
niklassaers

Reputation: 8830

Cocoapods spec that uses C++ and compiles as a framework

Quick summary: how can I add an include path to headers distributed with Xcode to a .podspec.json file?

I'm working on a Swift project where I want to include AudioKit as a dependency. For this project, I have to add 'use_frameworks!' in my Podfile

So I add my Pod in the Podfile (main repo hasn't been updated yet, which is why I point to the github repo directly)

pod 'AudioKit', :git => 'https://github.com/niklassaers/AudioKit.git'

and add in one of my Swift files

import AudioKit

then my compiler will warn me that CsoundFile.hpp is referencing iostream which cannot be found. iostream.h is in:

/Applications/Xcode62.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/c++/4.2.1/backward/iostream.h

Compared to stdlib.h which is in:

/Applications/Xcode62.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/stdlib.h

How can I add this header directory to the search path in the AudioKit.podspec.json (that I've forked).

I've made a sample project that demos what I've written above here: https://github.com/niklassaers/AudioKitSwiftFrameworkError - you can download it and compile it and you'll see the error message.

Upvotes: 2

Views: 2070

Answers (1)

marius
marius

Reputation: 7806

The main issue here is that the AudioKit.podspec.json is missing a public header definition. So all headers are considered to be public, including the C++ headers.

As there are no transitive imports from the Objective-C class headers, it should still work if only those are declared public:

"public_header_files": [
  "AudioKit/Core Classes/**/*.h",
  "AudioKit/Instruments/**/*.h",
  "AudioKit/Notes/**/*.h",
  "AudioKit/Operations/**/*.h",
  "AudioKit/Parameters/**/*.h",
  "AudioKit/Sequencing/**/*.h",
  "AudioKit/Tables/**/*.h",
  "AudioKit/Utilities/**/*.h"
],
…
"osx": {
   …
   "public_header_files": ["AudioKit/Platforms/OSX/classes/*.h"]
}
"ios": {
   …
   "public_header_files": ["AudioKit/Platforms/iOS/classes/*.h"]
}

Upvotes: 7

Related Questions