Undefined symbol OBJC_CLASS_$ when creating iOS framework

蹲街弑〆低调 提交于 2021-02-16 15:18:04

问题


I'm trying to build a iOS framework, to this, I'm using some dependencies and while building the framework project alone gives no error, when I install using CocoaPods in a demo app I get the following error Undefined symbol: _OBJC_CLASS_$_DFPRequest.

So this is what I have in the framework:

Podfile

platform :ios, '10.0'

use_frameworks!

target 'mylib' do  
  pod 'PrebidMobile'
  pod 'Google-Mobile-Ads-SDK'
  pod 'mopub-ios-sdk'
  pod 'GoogleAds-IMA-iOS-SDK'
end

MyLib.podspec

Pod::Spec.new do |s|

    ...

    s.platform      = :ios, "10.0"
    s.swift_version = '5.0'
    
    s.xcconfig = {
        :LIBRARY_SEARCH_PATHS => '$(inherited)',
        :OTHER_CFLAGS => '$(inherited)',
        :OTHER_LDFLAGS => '$(inherited)',
        :HEADER_SEARCH_PATHS => '$(inherited)',
        :FRAMEWORK_SEARCH_PATHS => '$(inherited)'
    }

    s.framework = [
      'CoreTelephony',
      'SystemConfiguration',
      'UIKit',
      'Foundation'
    ]
  
    s.subspec 'core' do |core|
      core.source_files = 'Source/**/*.{h,m,swift}'
    end

    s.dependency 'PrebidMobile'
    s.dependency 'Google-Mobile-Ads-SDK'
    s.dependency 'mopub-ios-sdk'
    s.dependency 'GoogleAds-IMA-iOS-SDK'

  end

Banner.swift

import UIKit
import PrebidMobile
import GoogleMobileAds
import MoPub

enum BannerFormat: Int {
    case html
    case vast
}

class BannerController: UIViewController, GADBannerViewDelegate, MPAdViewDelegate {

   @IBOutlet var appBannerView: UIView!

    @IBOutlet var adServerLabel: UILabel!

    var bannerFormat: BannerFormat = .html
    var adServerName: String = ""

    private var adUnit: AdUnit!
    
    private let amRequest = DFPRequest()
    private var amBanner: DFPBannerView!
    
    private var mpBanner: MPAdView!

    override func viewDidLoad() {
        super.viewDidLoad()
        adServerLabel.text = adServerName
    }

    override func viewDidDisappear(_ animated: Bool) {
        adUnit?.stopAutoRefresh()
    }

    func viewControllerForPresentingModalView() -> UIViewController! {
        return self
    }

}

Now in the appdemo, I have

Podfile

platform :ios, '10.0'
use_frameworks!
target 'appdemo (iOS)' do
  pod 'MyLib', :git => 'https://...mylib.git'
end

So, just by running pod install && pod update and building the appdemo I already got the error.

Since running the framework alone works, what am I doing wrong here that installing the framework does not work?

Ld /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/mylib/mylib.framework/mylib normal (in target 'mylib' from project 'Pods') cd /Users/user/appdemo/Pods /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target x86_64-apple-ios10.0-simulator -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.3.sdk -L/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/mylib -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/mylib -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/GoogleUtilities -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/PrebidMobile -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/PromisesObjC -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/mopub-ios-sdk -F/Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/nanopb -F/Users/user/appdemo/Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework-Current -F/Users/user/appdemo/Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework/ios-arm64_armv7 -F/Users/user/appdemo/Pods/Google-Mobile-Ads-SDK/Frameworks/GoogleMobileAdsFramework-Current/GoogleMobileAds.xcframework/ios-arm64_i386_x86_64-simulator -F/Users/user/appdemo/Pods/GoogleAds-IMA-iOS-SDK -F/Users/user/appdemo/Pods/GoogleAppMeasurement/Frameworks -F/Users/user/appdemo/Pods/GoogleUserMessagingPlatform/Frameworks/Release -F/Users/user/appdemo/Pods/GoogleUserMessagingPlatform/Frameworks/Release/UserMessagingPlatform.xcframework/ios-arm64_armv7 -F/Users/user/appdemo/Pods/GoogleUserMessagingPlatform/Frameworks/Release/UserMessagingPlatform.xcframework/ios-arm64_i386_x86_64-simulator -filelist /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/mylib.build/Objects-normal/x86_64/mylib.LinkFileList -install_name @rpath/mylib.framework/mylib -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/mylib.build/Objects-normal/x86_64/mylib_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/mylib.build/Objects-normal/x86_64/mylib.swiftmodule -framework AVFoundation -framework AdSupport -framework AudioToolbox -framework CFNetwork -framework CoreFoundation -framework CoreGraphics -framework CoreMedia -framework CoreTelephony -framework CoreVideo -framework Foundation -framework GoogleInteractiveMediaAds -framework MediaPlayer -framework MessageUI -framework MobileCoreServices -framework QuartzCore -framework Security -framework StoreKit -framework SystemConfiguration -framework UIKit -framework WebKit -weak_framework AdSupport -weak_framework JavaScriptCore -weak_framework SafariServices -weak_framework StoreKit -weak_framework WebKit -framework CoreTelephony -framework Foundation -framework MoPub -framework PrebidMobile -framework SystemConfiguration -framework UIKit -Xlinker -no_adhoc_codesign -compatibility_version 1 -current_version 1 -Xlinker -dependency_info -Xlinker /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/mylib.build/Objects-normal/x86_64/mylib_dependency_info.dat -o /Users/user/Library/Developer/Xcode/DerivedData/appdemo-gmoqpiaozrywmeguhfldbwybeebb/Build/Products/Debug-iphonesimulator/mylib/mylib.framework/mylib

Undefined symbols for architecture x86_64:
"OBJC_CLASS$_DFPRequest", referenced from: objc-class-ref in Banner.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)


回答1:


Since running the framework alone works

I'm not 100% sure I understand this; you can't "run" a framework alone. If you mean that the framework builds, that's not surprising; the missing symbol is from a different library, and that doesn't have to be resolved until your framework is eventually linked into an application.

what am I doing wrong here that installing the framework does not work?

Hard to say for certain, but I'd bet that it might have something to do with your app's Podfile:

pod 'MyLib', :git => 'https://...mylib.git'

The podspec for MyLib should be in the root directory of that repo, so check that the URL points to where you think it does, that MyLib.podspec is in the root of that repository, and that the podspec is correct.

Run pod install and then pod update (running them separately is a good idea when troubleshooting so that you know for certain which one produced any errors or other output). Open up your app's workspace and find the file that defines the DFPRequest class. If you can't find it, you'll need to dig deeper into your pods setup to figure out what the problem is. If you do find the file, then your pods setup is probably OK; instead, check your project configuration and make sure that the file is actually included in the target you're trying to build.



来源:https://stackoverflow.com/questions/65904002/undefined-symbol-objc-class-when-creating-ios-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!