Search code examples
iosobjective-cxcodeios-simulator

Undefined symbol: _OBJC_CLASS_$_ only on simulator


Im sure this is something that will be easy for someone with more objective C experience than me. I did not write this but I am stuck using it.

I have a .h file: bleconfigLibrary with an interface:

@interface bleconfigLibrary : NSObject.  

In a different .m file I have:

#import <Foundation/Foundation.h>
#import "BTCommands.h"
#import "bleconfigLibrary.h"
#define MAX_BUF_SIZE                (512)
@implementation BTCommands
bleconfigLibrary *handleRequest;

+ (void)initialize{
   handleRequest = [bleconfigLibrary alloc];
}   

The problem seems to be:

handleRequest = [bleconfigLibrary alloc];

When I try to run on a simulator I get the error:

Undefined symbol: _OBJC_CLASS_$_bleconfigLibrary

But it runs fine on physical devices. If I comment out that section, it runs on the simulator. Any help would be appreciated.


Solution

  • You've defined an @interface for bleconfigLibrary, but you haven't defined an @implementation for it in the code you've shown here. The fact that it works on physical devices but not the simulator suggests you're linking a library that defines an implementation, but that library isn't built for simulator. Possibly it's an old-style "fat" library that wasn't built for Apple Silicon. The library would need to be rebuilt as an xcframework. (While the linked page discusses Swift, xcframeworks are applicable to ObjC as well.)

    But note that BLE functionality generally does not work in the simulator anyway, so you may prefer to simply not build this code for simulator.

    This line is incorrect:

    handleRequest = [bleconfigLibrary alloc];
    

    That allocates memory, but does not initialize the object. While it might "work" (if, for example, the object happens not to need initialization), the correct line here is, assuming ARC is enabled:

    handleRequest = [bleconfigLibrary new];
    

    or equivalently, whether ARC is or isn't enabled:

    handleRequest = [[bleconfigLibrary alloc] init];
    

    As a side note, ObjC classes should begin with an uppercase letter (though it's not mandatory). The normal capitalization convention here would be BLEConfigLibrary.

    (I'm assuming the . at the end of your @interface definition is a typo in your question, since it wouldn't compile in ObjC.)