06-30 00:00
Notice
Recent Posts
Recent Comments
06-30 00:00
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Archives
Today
Total
관리 메뉴

pear

[iOS]3rd part framework project 2 - modulemap setting(c API Support) 본문

iOS/swift

[iOS]3rd part framework project 2 - modulemap setting(c API Support)

pearlab 2021. 11. 11. 16:28

Sample Project Guide

add c header

simpleC.hpp

#define EXTERN_API extern "C"

#include <stdio.h>

EXTERN_API void test();

 

simpleC.cpp

#include "simpleC.hpp"

EXTERN_API void test()

{

}

 

Project->Build Setting->Filtter (Mach)->Linking (static Library SDK배포용)

*처음 개발단계에서는 디버깅을위해 dynamic 사용

 

build

products->target(ex.Debug-iphonesimulator)->projectname.framework->Modules->module.modulemap 

코드 복사

 

framework module simplelib {

  umbrella header "simplelib.h"

 

  export *

  module * { export * }

}

 

module simplelib.Swift {

    header "simplelib-Swift.h"

    requires objc

}

 

framework module 부분만 사용하여 simplelib.modulemap 작성

 

module map에서 import 할 header public으로 설정

target project -> build phases -> Header

 

 

framework module simplelib {

  umbrella header "simplelib.h"

 

  export *

  module * { export * }

[Todo]3rd pard c API class

explicit module simpleC{

      header "simpleC.hpp"

      export *

  }

}

simplelib.modulemap setting

Project->Build Setting->Filtter (module)->Packaging->Module Map File

simplelib.modulemap setting

 

[Todo]부분에 C API Header modlue 추가 작성

C header 경로 편의를 위해 Header Search Paths 추가

Project->Build Setting->Filtter (header)->SearchPaths->Header Search Path (${SRCROOT}/mypath)

header search paths setting

products->target(ex.Debug-iphonesimulator)->projectname.framework->Modules->module.modulemap 적용 확인

framework module simplelib {

  umbrella header "simple.h"

 

  export *

  module * { export * }

  

  explicit module simpleC{

      header "simple.h"

      link "simpleC"

      export *

}

}

 

module simplelib .Swift {

    header "simplelib -Swift.h"

    requires objc

}

 

최종 SourceTree

source tree

 

시행착오

처음 C API modulemap 만 생성하여 3rd part framework를 만들어 사용 시

Sample 프로젝트에서 빌드가 잘되는 듯 하였으나

framework 프로젝트가 해당경로에서 삭제되고나면 link(Missing required module) 이슈 발생!!

해당 정보가 설정된 위치를 확인 하지 못하였으나 modulemap에 대해 framework 프로젝트 경로를 참조하는 link 이슈 원인 확인!!

 

몇몇 stack overflow에서는 프레임워크 내부에 생성된 modulemap을 수정하도록 가이드 하지만 배포 관리상 매우 불편함!!

 

빌드된 framework 내부에  modulemap을 추가하여 사용이 가능하나 관리에 문제 이슈 있음!!

modulemap을 직접 등록하여 내부 module로 추가하여 modulemap을 빌드 배포 할수 있도록 함.

현재 까지 modulemap의 3rd 활용에 대한 가이드 문서는 찾지 못함.

 

 

추가  정보

C API 정보를 숨시고 싶으면

Project->Build Phases->Header public에서 private로 C Header를 이동한다.

 

Edit ADD

build library for distribution Setting ADD

빌드 설정을 활성화하면 컴파일러는 프레임워크를 빌드할 때마다 Swift Module Interface 포맷의 파일인 .swiftinterface파일을 생성합니다.

reference

http://minsone.github.io/ios/mac/ios-wwdc-2019-binary-frameworks-in-swift-little-summary-and-translate

next

3rd part framework project 3 - XCFramework(Fat Framework)

'iOS > swift' 카테고리의 다른 글

3rd part framework project 3 - XCFramework(Fat Framework)  (0) 2021.11.15
[iOS]swift record - 1  (0) 2021.11.11
[iOS]3rd part framework 사용 App 만들기  (0) 2021.11.11
[ios]3rd part framework project 1 - create  (0) 2021.11.11
swift study start  (0) 2021.11.11