skip to Main Content

I refactored some code in my iOS app and have started receiving the following error

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

So here is what I did..

Earlier I had all the files at root. To organise I moved all files under new folder vendor/ios-startup-reporter/{files}.{h,m}

Then created a file vendor/StartupReporter.h which contains following content

#import "ios-startup-reporter/UBApplicationStartupReasonReporterNotificationRelay.h"
#import "ios-startup-reporter/UBApplicationStartupReasonReporter.h"
#import "ios-startup-reporter/UBApplicationStartupReasonReporterPriorRunInfo.h"
#import "ios-startup-reporter/UBApplicationStartupReasonReporterPriorRunInfoProtocol.h"

now, In AppDelegate When I import it like this (#import "vendor/StartupReporter.h")

#import <React/RCTBridgeDelegate.h>
#import <UIKit/UIKit.h>
#import <UserNotifications/UNUserNotificationCenter.h>
#import "vendor/StartupReporter.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate, UNUserNotificationCenterDelegate>

@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) UBApplicationStartupReasonReporterNotificationRelay *notificationRelay;

@end

I get the above error,

Can someone help me what I am doing wrong and how I can fix it?

2

Answers


  1. I’ve had this issue with react-native and XCode for some time on my M1 Mac (albeit a different library), generally the following does help fix the issue:

    Clean Project

    1. Clean the project CMDK
    2. Clear the derived data
    rm -rf ~/Library/Developer/Xcode/DerivedData
    
    1. Close XCode
    2. Run the following in your Pods directory:
    pod cache clean --all
    rm -rf Pods
    pod install --repo-update
    
    1. (optional) Fresh npm install
    2. Restart XCode

    Check Linked Libraries

    If the above doesn’t fix the issue make sure that there isn’t any artifacts left over from before your refactoring. There may be a couple places to check for linked libraries that were renamed or don’t exist anymore.

    Check Targets > Build Phases > Link Binary with Libraries

    Login or Signup to reply.
  2. First of all, if the header file is in the same module as the AppDelegate, do not import it by the relevant path, but import it by the filename:

    #import "vendor/StartupReporter.h"
    

    to

    #import "StartupReporter.h"
    

    It will be found and correctly imported.

    Secondly, make sure that all .m files are linked to the app target.
    Undefined symbols means that the class name is recognizable by the compiler, but the symbols (actual implementation) cannot be found. Usually, this happens when we create an {h,m} file and forget to add the .m file to the target membership.

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search