简体   繁体   中英

Weak linking a framework to a static library

Problem

My project is arranged like this:

  • App
    • Framework
      • Static library (common code)

The static library is going to start depending on the GoogleWebRTC framework. Unfortunately, this dependency can only be built as a framework via WebRTC.org . They removed the ability to build as a static library for maintenance reasons.

Question

Is is possble for the static library to weakly link to the GoogleWebRTC framework?

  • App
    • Framework
      • Static library ("CommonCode")
    • GoogleWebRTC

Some solutions that come to mind are:

  • Including the WebRTC header files in the static library, and build with a custom modulemap so that the include "<WebRTC/WebRTC.h> works. Then embedding and linking the library in the App target
  • Somehow converting the GoogleWebRTC.framework to a static library and embed the headers and binary in the "CommonCode" static lib
  • I... can't remember the other solution I had in mind. I'll update this when I remember.

It's unfortunate decision on Google's part to remove static target.

if that helps, you can use mesibo webrtc framework which is a static framework build using modified ninja files . Only downside is, it is not as regularly updated as Google build (typically lags by a month old sync).

https://github.com/mesibo/mesibowebrtcframework

All you have to do is to copy WebRTC.framework/WebRTC from mesibo version which is nothing but a static library, extract using lipo -extract and repackage it with your own library using lipo -create .

Below is the difference you will see in Mesibo and Google Version of WebRTC framework

Mesibo version

$ file WebRTC.framework/WebRTC
WebRTC.framework/WebRTC: Mach-O universal binary with 4 architectures: [i386:current ar 
archive random library] [arm64]
WebRTC.framework/WebRTC (for architecture i386):    current ar archive random library
WebRTC.framework/WebRTC (for architecture armv7):   current ar archive random library
WebRTC.framework/WebRTC (for architecture x86_64):  current ar archive random library
WebRTC.framework/WebRTC (for architecture arm64):   current ar archive random library

And Google Version

$ file WebRTC.framework/WebRTC
WebRTC.framework/WebRTC: Mach-O universal binary with 4 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64]
WebRTC.framework/WebRTC (for architecture x86_64):  Mach-O 64-bit dynamically linked shared library x86_64
WebRTC.framework/WebRTC (for architecture i386):    Mach-O dynamically linked shared library i386
WebRTC.framework/WebRTC (for architecture armv7):   Mach-O dynamically linked shared library arm_v7
WebRTC.framework/WebRTC (for architecture arm64):   Mach-O 64-bit dynamically linked shared library arm64

Let me know if you need more inputs!

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