Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

podspec file: keep folder structure of public C headers?

I'm trying to add a c code to my react native plugin for the iOS part, but I'm always getting the error that the header files could not find each other.

My .podspec

require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))

Pod::Spec.new do |s|
  s.name         = package["name"]
  s.version      = package["version"]
  s.summary      = "SUMMARY"
  s.homepage     = "HOMEPAGE"
  s.license      = package["license"]
  s.authors      = package["author"]
  s.platforms    = { :ios => "11.0" }

  s.source       = { :git => "MyGitLink", :tag => "v#{s.version}" }
  s.source_files = "ios/**/*.{h,m,swift}"

  s.swift_version = "5.0"

  s.dependency "React"
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
  s.vendored_frameworks = 'ios/Frameworks/MyFramework.framework'
  s.public_header_files = 'ios/Frameworks/MyFramework.framework/**/*.h'
  s.preserve_paths = 'ios/Frameworks/MyFramework.framework/Frameworks/MySecondFramework.framework/Sphinx/include'
end

The path ios/Frameworks/MyFramework.framework/Frameworks/MySecondFramework.framework/Sphinx/include contains a module.modulemap and two folders ("sphinxbase" and "pocketsphinx") with C header files.

My generated umbrella file is this:

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif

#import "cmdln_macro.h"
#import "pocketsphinx.h"
#import "pocketsphinx_export.h"
#import "ps_lattice.h"
#import "ps_mllr.h"
#import "ps_search.h"
#import "ad.h"
#import "agc.h"
#import "bio.h"
#import "bitarr.h"
#import "bitvec.h"
#import "byteorder.h"
#import "case.h"
#import "ckd_alloc.h"
#import "clapack_lite.h"
#import "cmd_ln.h"
#import "cmn.h"
#import "err.h"
#import "f2c.h"
#import "fe.h"
#import "feat.h"
#import "filename.h"
#import "fixpoint.h"
#import "fsg_model.h"
#import "genrand.h"
#import "glist.h"
#import "hash_table.h"
#import "heap.h"
#import "jsgf.h"
#import "listelem_alloc.h"
#import "logmath.h"
#import "matrix.h"
#import "mmio.h"
#import "ngram_model.h"
#import "pio.h"
#import "prim_type.h"
#import "priority_queue.h"
#import "profile.h"
#import "sbthread.h"
#import "sphinxbase_export.h"
#import "sphinx_config.h"
#import "strfuncs.h"
#import "yin.h"
#import "MyFramework-Swift.h"
#import "MyFramework.h"

FOUNDATION_EXPORT double MyPluginVersionNumber;
FOUNDATION_EXPORT const unsigned char MyPluginVersionString[];

cmdln_macro.h imports cmd_ln.h (#include <sphinxbase/cmd_ln.h>) and the error

'sphinxbase/cmd_ln.h' file not found

occurs.

I was hoping that s.preserve_paths could keep the structure, but it didn't. Setting s.header_mappings_dir to the include path didn't work either.

like image 695
chocolate cake Avatar asked Aug 14 '26 13:08

chocolate cake


1 Answers

Update 2023; At time of writing, Xcode and/or the compiler does not support any kind of folder structure.

Meaning:

  • Each header should have a unique name (unique in the hosting Framework, not entire world).
  • And the umbrella/bridging header should include it by said name, without any folder structure.
  • The only folder that the umbrella header supports is the Module-name, like:
#import <MyFramework/MyPublicHeader.h>

Note that MyFramework folder is virtual, meaning the compiler magically maps it to MyFramework module's "Headers" folder (which is a real folder).


Also, OP sets public_header_files manually, if we remove that, by default all headers added to source_files are made "public" by cocoapods (and get auto included in the auto generated umbrella header, generated by cocoapods).

like image 111
Top-Master Avatar answered Aug 19 '26 13:08

Top-Master



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!