简体   繁体   中英

Trying to integrate C++ code into a Swift framework project with XCode - fails

I'm trying to integrate C++ code (fuzzylite.com) into a Swift framework project and I keep receiving build errors. From what I understand, you cannot use a bridging header in Swift framework projects, rather you need to include the source in the Umbrella headers. I wrapped the C++ code in Objective-C classes and then included the Objective-C headers in the umbrella header as such:

#import <Fuzzylite/ObjCWrapper.h>

Followed all the steps as mentioned here ( Clarification on adding Objective C code to a swift dynamic framework ) but it doesn't really work because it is not able to find the Objective-C wrapped C++ framework. Any help is highly appreciated!

Solved it by doing the following:

  1. Added C++ source directory into XCode project
  2. Expose C function wrappers to C++ instance methods
  3. Created C header file wrapper for the C++ project like such:

     #ifndef Header_h #define Header_h #ifdef __cplusplus extern "C" { #endif void hello(char *str); #ifdef __cplusplus } #endif #endif /* Header_h */
  4. In the Umbrella header file (in my case the name of the Umbrella header file was 'TestSDK.h') for the framework project (remember that since this was a framework target, there was no bridging header involved as is the case when building an app), I put the following.:

     #ifdef __cplusplus #import "fuzzylite/fl/Headers.h" #endif
  5. Added the -I/ to XCode->Target->Build Settings->Other C Flags. In my case, the path was:

     -I$(PROJECT_DIR)/TestSDK/fuzzylite/

This worked for me. Without step 5, I was getting path include errors.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM