I am getting this error for a single class from a static library, which I have compiled myself. It has all been working fine and I wanted to add another class as a simple data transfer object called PPClientData.
The error is:
Undefined symbols for architecture armv7:
"_OBJC_CLASS_$_PPClientData", reference from: objc-class-ref in
CPPIntegrationDelegate.o
The relevant file is included in the library compile targets and I have used otool -d on the (fat) library and it shows
libPPIntegration.a(PPClientData.o) (architecture armv7):
(__DATA,--data) section
The header for the class (PPClientData.h), which is included in the app is like this:
#import <Foundation/Foundation.h>
#interface PPClientData : NSObject
#property(nonatomic, strong) NSString* clientId;
// 3 others identical to the above with different names
#end
and the .m file which should be compiled into the library looks like this:
#import "PPClientData.h"
#implementation PPClientData
#synthesize clientId;
//Synthesize others
-(id)init {
self = [super init];
return self;
}
#end
It is consumed in a single class in the app as follows. If this one function that consumes it is commented out, the linker error goes away (it links to other classes in the library) but with this in, it fails. This is a delegate function for the library.
#import "CPPIntegrationDelegate.h"
#import "PPClientData.h"
#implementation CPPIntegrationDelegate
// Various other functions that work fine
-(PPClientData*)clientData:(PPIntegration*)integration {
PPClientData* dict = [[PPClientData alloc]init]; // This is the line that causes the linker error
dict.clientId = #"whatever";
// set other properties of dict
return dict;
}
I understand what the linker is trying to do and what the error suggests but I don't see what I've missed. Can anyone help?
If you are on Xcode 5.1, try to remove arm64 from Valid Architectures (under Build Settings) and also change the Architectures from "Standard architectures" to just armv7 and armv7s. This might be relevant to you: how to stop xcode5.1 building for 64bit
Well, it wasn't the architectures causing the problem but in some way, xcode or whatever had been confused by the order of the forward declaration of the class I was using and then the definition itself. Initially, the broken code was something like:
BrokenClass.h
// Definitions etc.
GoodClass.h
#class BrokenClass;
- (BrokenClass*)someMethod:(SomeType*) param;
GoodClass.m
#import "BrokenClass.h"
- (BrokenClass*)someMethod:(SomeType*) param
{
}
Which was included into my App by including GoodClass.h into a header file, which forward declared BrokenClass and then included BrokenClass.h into an m file which should have completed the definition, where the class was used.
Anyway, to fix it, I changed the GoodClass code to:
GoodClass.h
#import "BrokenClass.h"
- (BrokenClass*)someMethod:(SomeType*) param;
Removed the #import in the m file and then only included the one GoodClass.h into my app (which brought in the BrokenClass).
Whether this is a bug somehow or more likely, I had too many forward declarations etc. I'm not sure.
Related
I have big problem with one part of my code.
I have simple function in my ViewController.swift file (on end):
ViewController.swift
#objc class Constant: NSObject {
override init() {}
#objc class func parseApplicationId() -> String { return "lol" }
#objc func printSome() { print("teeeeest") }
}
Now I have one pod (charts graphic) what was written in Objective-C. So I created Bridging file called:
myprojectname-Swift.h
#import "EColumnChartViewController.h"
In header file of Objective-C file:
HEADER.h
#import <UIKit/UIKit.h>
#import "EColumnChart.h"
#import "myprojectname-Swift.h"
#class Constant;
#interface Constant : NSObject
-(void)printSome;
#end
and in my FILE.m I have this:
#import "myprojectname-Swift.h"
- (void)viewDidLoad
{
[super viewDidLoad];
Constant * sis = [[Constant alloc] init];
[sis printSome];
}
My problem is:
When I build a project, Xcode call me error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_Constant", referenced from:
objc-class-ref in EColumnChartViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What I trying to make solution:
New Bridging file
Switching off some parts of Build Settings
#implementation Constant -> Thread 1 error
I just want to call Swift function into Objective-C file (easy call print console). Thanks for every idea.
Last words: I've checked so many posts on Stackoverflow.
Duplicate classes
The main issue appears to be that you have created two classes named Constant: one in Swift and another in Objective-C. You can only have one class with a given name.
This #objc class Constant: NSObject and #interface Constant : NSObject both create the same class. Rename one of these.
Possibly incorrect bridging
The Swift bridging header is special. You can't just create a header file and expect that to work in Swift.
Ensure that the bridging header is properly set in Xcode.
Click the project at the top to open the config screen
Search for SWIFT_OBJC_BRIDGING_HEADER
Make sure the value points to your bridging header. For example: myprojectname/myprojectname-Bridging-Header.h
In the bridging header file, put the Objective-C import for the class that you want Swift to be able to use: #import "EColumnChartViewController.h"
Other Issues
In HEADER.h:
remove #class Constant;. This is doing nothing for you.
Move the #import for EColumnChart.h and myprojectname-Swift.h into the .m file only.
The FILE.m should have an #import HEADER.h. Every .m must import it's .h!
On the line #objc class Constant: NSObject, remove the #objc... it's obviously Objective-C because it extends NSObject.
As some commenters have stated, you have provided code with an astonishing number of problems. You should really take the time to learn Objective-C and/or Swift first. Start by watching some of the free WWDC videos or Googling for intro to iOS.
Make step by step above
You use #objcMembers above declare class in swift file.
Import <"Your_Project">-Swift.h in .m file.
objcMembers
class ObjectA: NSObject {
.....
}
I have two header of a class and it's extension(generated by Xcode for NSManaged object). But I'm getting a linker error and I figured out it was due to a circular reference.
Conversation+CoreDataClass.h
NS_ASSUME_NONNULL_BEGIN
#interface Conversation : NSManagedObject
#end
NS_ASSUME_NONNULL_END
#import "Conversation+CoreDataProperties.h"
Conversation+CoreDataProperties.h
#import "Conversation+CoreDataClass.h"
NS_ASSUME_NONNULL_BEGIN
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
NS_ASSUME_NONNULL_END
You can clearly see the circular reference here. I found this question where the problem was to add a #class declaration and remove the header. So I commented out the import statement in the Conversation+CoreDataProperties.h and added #class Conversation;. Now two errors pop up saying it's an undefined class. Have attached the screenshot of the error below. I don't quite understand why this is happening and what I need to do to fix it. Any help is much appreciated. Thanks!
Linker error
duplicate symbol _OBJC_CLASS_$_Conversation in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/Conversation+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_Conversation in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/Conversation+CoreDataClass.o
duplicate symbol _OBJC_CLASS_$_ConversationDate in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/ConversationDate+CoreDataClass.o
duplicate symbol _OBJC_METACLASS_$_ConversationDate in:
/Users/xxx/Library/Developer/Xcode/DerivedData/xxx-gbhivuwptwzhkldfbmjghkokozgn/Build/Intermediates/xxx.build/Debug-iphoneos/xxx.build/Objects-normal/arm64/ConversationDate+CoreDataClass.o
ld: 4 duplicate symbols for architecture arm64 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
So I commented out the import statement in the Conversation+CoreDataProperties.h and added #class Conversation;.
You may only do this if you're aren't using any of the Convention class's interface (for instance declaring a property of type Convention. You can't do this if you're extending Convention via a category or class extension.
You have a legit circular reference here you must resolve. You can either:
Move the class and the category into the same source file (if there's no special reason this needs to be in a category you could just move the declaration of fetchRequest into the class itself).
Stop importing +CoreDataProperties.h in the class header, and import it instead wherever callers need to be calling fetchRequest.
the duplicate symbols warning do result because
You have the class multiple times in your project and the compiler does not know, which to choose (then it is mostly a duplicate linking error)
There is something wrong with your ConversationDate+CoreDataClass
Just a question that raised from your source code: why do you import an extension of the class you want to extend?
#import "Conversation+CoreDataClass.h"
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
All the extension class usually needs to know are basically the classes they extend:
#import "Conversation.h"
#interface Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest;
#end
Only the implementation file (.m) would have to import the header file. E.g:
#import "Conversation+CoreDataClass.h"
#implementation Conversation (CoreDataProperties)
+ (NSFetchRequest<Conversation *> *)fetchRequest {
// body
return nil;
}
#end
And last question: Are you sure there exists no other class extension with the same name in your project? CoreData might also have created them itself.
Please have a look in your xCode Project like this:
Found the solution to my problem in this answer. I just had to remove the .m files from the Compile Sources.
I have an iOS app and am using XCode Version 6.3.1 (6D1002).
I have a m file in which I define
#interface CustomObject:NSObject {} #end
and I try to use in viewDidLoad as
CustomObject* obj = [[CustomObject alloc]init];
When I run this, I get linkage errors saying
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_CustomObject", referenced from:
objc-class-ref in ChooseAlbumViewController.o
ld: symbol(s) not found for architecture x86_64
I have similar interfaces defined for other objects and those continue to build, link and run fine. Any new interfaces I'm defining are failing with these linkage errors. I could use some help to figure out what's causing this. I'm new to iOS development so if I'm missing information crucial to figure this out please let me know and I'll add it.
Few flags from my Build Settings that might help -
Build Active Architecture Only = YES
Architectures = Standard Architecture armv7 armv64
Valid Architectures = arm64 armv7 armv7s
Here is the code in which I define the interface and try to use it
#interface CustomAlbum : NSObject {
}
#end
#implementation ChooseAlbumViewController
{
}
- (void)viewDidLoad {
[super viewDidLoad];
CustomAlbum* a = [[CustomAlbum alloc] init];
}
Figured it out, the problem was that I had only defined an interface but had not defined an implementation. Adding
#implementation User
#end
to the .m file solved the linkage issues.
Thanks for the help guys
Most of the time, this happens when your class isn't being compiled into the target you want. Select the .m file that CustomObject is in and check the right sidebar. In the first tab, there should be a list of targets. Check ✔️ your current target so that Xcode compiles it.
while compiling the source file ChooseAlbumViewController looks for a corresponding header. The header named CustomAlbum doesn't match. This causes the error message.
I just started porting an Android app to iOS, and am hitting a major roadblock that I can't figure out despite scouring many similar questions.
I am attempting to follow the pattern implemented in the CastVideos sample where the GoogleCast API is encapsulated in a singleton class which I've called CastManager. To use my singleton class, I #import "CastManager.h" in AppDelegate.m. Then in CastManager.h, I #import <GoogleCast/GoogleCast.h> so that I can use classes and protocols from it as part of CastManager's public interface. However, because I'm importing CastManager.h in both CastManager.m and AppDelegate.m, the linker is finding duplicate symbols from the GoogleCast framework.
This is my CastManager.h:
#import <GoogleCast/GoogleCast.h>
#import <Foundation/Foundation.h>
#interface CastManager : NSObject
#property(nonatomic, strong) GCKDeviceScanner *deviceScanner;
+ (instancetype)sharedCastManager;
#end
And corresponding CastManager.m:
#import "CastManager.h"
#implementation CastManager
+ (instancetype)sharedCastManager {
NSLog(#"sharedCastManager");
static CastManager *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
singleton = [[self alloc] init];
});
return singleton;
}
- (instancetype)init {
NSLog(#"init()");
if (self = [super init]) {
self.deviceScanner = [[GCKDeviceScanner alloc] init];
}
return self;
}
#end
And this is the main part of my AppDelegate.m:
#import "AppDelegate.h"
#import "CastManager.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CastManager *castManager = [CastManager sharedCastManager];
return YES;
}
However, this results in the following error from the linker when attempting to build the project:
duplicate symbol _kGCKDeviceCapabilityVideoOut in:
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/AppDelegate.o
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/CastManager.o
... many similar errors ommitted for brevity ...
duplicate symbol _kGCKDeviceCapabilityAudioIn in:
/Users/nate/Library/Developer/Xcode/DerivedData/MyCastApp-ezrgxdnlvywpanerezulnarzknno/Build/Intermediates/MyCastApp.build/Debug-iphonesimulator/MyCastApp.build/Objects-normal/x86_64/AppDelegate.o
/Users/nate/Projects/MyCastApp/GoogleCast.framework/GoogleCast(GCKDevice.o)
ld: 8 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
As far as I can tell, this exactly copies the pattern as defined in the CastVideos sample, but the sample compiles fine, and mine doesn't, and I've scoured through both projects trying to find what is different, but I just don't see it. Further, I don't see anything really wrong with doing this, and would expect it to work fine. I can't think of any other way to do it, really.
Here are the relevant files from the CastVideos sample for comparison:
ChromecastDeviceController.h
ChromecastDeviceController.m
AppDelegate.m
Other questions point to solutions that don't apply or don't fix it:
I'm not importing a .m file on accident.
I don't have duplicate references to any files in the project.
The "Compile Sources" section of the "Build Phases" project setting doesn't include any duplicates.
I've added the '-ObjC' linker flag as described by the GoogleCast API docs, though it has the same error with or without it.
I've tried deleting the delegate data and doing a clean before building.
This is with Xcode 6.3.1 running on OS X Yosemite 10.10.3 and the GoogleCastSDK-2.6.0 package from the SDK documentation page
I have checked in my sample project with the problem at https://github.com/nshafer/MyCastApp
Any help is greatly appreciated!
Edit: the duplicate is somewhat related, it's definitely about the same symbols, but the answers there didn't help, as I'm not using Object-C++, but rather just Objective-C. I don't have a .mm file, just a .m file.
For me it helped to switch the "No Common Blocks" compiler setting to NO:
It pretty much seems to make sense, the setting is explained here: What is GCC_NO_COMMON_BLOCKS used for?
The linker tells you that you have a variable named kGCKDeviceCapabilityVideoOut in two files, AppDelegate.m and CastManager.m. Since it's not in your source code, it's most likely in the GoogleCast code that you are including.
Either change the GoogleCast.h file, or make sure it is only included in one .m file. Including it from CastManager.h means it is indirectly included in every file that includes CastManager.h, so I would avoid that and only include it from CastManager.m. You'll probably have to add
#class GCKDeviceScanner;
in your CastManager.h file.
I found another fix, which is to edit GCKDevice.h in the GoogleCast.framework/Headers folder. Change the 4 constants from GCK_EXPORT to GCK_EXTERN near the top of the file.
/** Device capability flag for video out. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityVideoOut;
/** Device capability flag for video in. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityVideoIn;
/** Device capability flag for audio out. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityAudioOut;
/** Device capability flag for audio in. */
GCK_EXTERN const NSInteger kGCKDeviceCapabilityAudioIn;
I detailed this in a bug report I filed with Google's issue tracker, but it was marked as a duplicate of another somewhat related issue. Either way, it will perhaps get fixed in the next version. Until then, I would suggest going with changing the "No Common Blocks" setting as detailed in Joobik'com's answer, as that doesn't involve changing the 3rd party code.
I'm trying to build and test an app with the xcode simulator, but during the building I get errors in ACAccount.h, ACAccountType.h, etc.
The "strange thing" (at least for me as i'm completely new in using xcode) is that if I click on the .h files with errors they do not appear under the project code but under
Simulator - iOS 7.1-> Frameworks -> Accounts -> ACAccount.h
which is unmodifiable.
Examples of the errors are:
line:
#class ACAccountType,ACAccount Credential; --> Illegal interface qualifier
ACCOUNTS_CLASS_AVAILABLE(NA, 5_0)
#interface ACAccount : NSObject -->Objective-C declarations may only appear in global scope
If the .h are predefined files.. How can I solve these errors?
Many thanks in advance!
Generally when you encounter items like the 'illegal interface qualifier' in system provided headers it indicates that you've placed the #import statement within an #interface block, like:
#interface foo ()
#import <Accounts/ACAccount.h>
#end
This generates errors about the content in the file being imported (e.g. your illegal interface qualifier error), while the actual issue is that putting #import statements within an #interface block is invalid.
You should put #import statements together at the top of the file, outside of any #interface or #implementation blocks.
If you put it into the #implementation section, the error becomes:
error: Objective-C declarations may only appear in global scope