Can’t create a React Native project in Swift. Linker won’t link against current architecture

So, I’ve been racking my brain with this bug I have. I inherited this React Native bridge module. It calls a library that I wrote in Swift. I’ve managed to fix a few issues with it, but now there’s one issue with the linker that I can’t simply wrap my head around:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_RNModuleSdk", referenced from:
      objc-class-ref in RNModuleSdk-eba6e9a8c28f116def4103b848536d6fd0a1a766f6fb5a382f24541d40db702c.o
      __OBJC_$_CATEGORY_RNModuleSdk_$_RCTExternModule in RnModuleSdk-eba6e9a8c28f116def4103b848536d6fd0a1a766f6fb5a382f24541d40db702c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I think the issue stems from the linker not being able to see either RNModuleSdk or, more likely, RCTExternModule. To me, this makes sense because the architecture it complains about changes relative to the target I’m aiming for (a device or the simulator, arm64 or x86-64, respectively)

This is really my first React Native project, so I’ve been comparing what I have with other sites to see if I missed something in the Native Bridge, but so far nothing stands out. Abstracted code below


import Foundation
import UIKit
import ModuleSdk

class RNModuleSdk: NSObject {


#import <React/RCTBridgeModule.h>
//#import "React/RCTViewManager.h"
@interface RCT_EXTERN_REMAP_MODULE(SdkManager, RNModuleSdk, NSObject)


#import <React/RCTBridgeModule.h>
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import <React/RCTRootView.h>
#import <React/RCTUtils.h>
#import <React/RCTConvert.h>
#import <React/RCTBundleURLProvider.h>

I use the RCT_EXTERN_REMAP_MODULE function so it matches with the name the javascript code expects it to be. I’ve tried before with just RCT_EXTERN_MODULE, I get the same error.

I’ve checked the library search paths, everything seems to be in order (though, if I’m missing linking against a React or React Native library, I’m unsure). The project uses Cocoapods and has at the end the use_native_modules! line, which I think handles the linking for me? I could be wrong, which would make everything make sense, but I’m at my wit’s end and don’t know what else to do.



So, after much experimentation and rebuilding the project, I discovered the cause for my issue. Turns out that I was using a variable that used a custom variable type defined in the Module A library that I wrote. My guess, the linker was confused by the variable type because it technically wasn’t aware of it, causing it to complain the manner in which it did.

It was totally non-intuitive and the only way I discovered this was by rewriting the native module from scratch and reintroducing elements line-by-line. So, if anyone later on is reading this, encountering a similar issue and you’re writing a React Native module based on a library you wrote, check your variables: they may be the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *