Calling another class's init causes Linker error (Objective-C) - objective-c

I'm using a class called AudioFile in another class called MyManager. Trying to use other methods from AudioFile gives no errors and will build out. But if I try to use use AudioFile's init, I get a linker error when I try to build.
Note: I still get the error even if I call init from somewhere else in MyManager
MyManager.mm
#property(nonatomic,retain)AudioFile *audioFile;
-(id)init
{
if((self = [super init]))
{
}
self.audioFile = [[AudioFile alloc] init];
return self;
}
AudioFile.m
- (id)init
{
//initializer stuff
return self;
}
error looks like this:
Undefined symbols for architecture arm64:
"_OBJC_CLASS_$_AudioFile", referenced from:
objc-class-ref in myManager.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Related

CocoaLumberjack - change log file name by subclassing the LogFileManager

I am trying to change the logfile name. What i've found so far is this.
My subclass of DDLogFileManagerDefault looks like this:
LogFileManager.h
#import CocoaLumberjack;
// this import would work as well
// #import <CocoaLumberjack/CocoaLumberjack.h>
// but none of these
//#import "DDLog.h"
//#import "DDTTYLogger.h"
//#import "DDASLLogger.h"
//#import "DDFileLogger.h"
#interface LogFileManager : DDLogFileManagerDefault
#end
LogFileManager.m
#import "LogFileManager.h"
#implementation LogFileManager
- (NSString *)newLogFileName {
NSBundle *bundle = [NSBundle mainBundle];
NSDictionary *info = [bundle infoDictionary];
NSString *appName = [info objectForKey:#"CFBundleExecutable"];
NSString *timeStamp = [self getTimestamp];
return [NSString stringWithFormat:#"%#%#.log", appName, timeStamp];
}
- (BOOL)isLogFile:(NSString *)fileName {
return NO;
}
- (NSString *)getTimestamp {
static dispatch_once_t onceToken;
static NSDateFormatter *dateFormatter;
dispatch_once(&onceToken, ^{
dateFormatter = [NSDateFormatter new];
[dateFormatter setDateFormat:#"YYYY.MM.dd-HH.mm.ss"];
});
return [dateFormatter stringFromDate:NSDate.date];
}
#end
This is how I use it:
DDLogFileManagerDefault *documentsFileManager = [[LogFileManager alloc] init];
DDFileLogger *fileLogger = [[DDFileLogger alloc] initWithLogFileManager:documentsFileManager];
When I replace LogFileManager with DDLogFileManagerDefault it works fine. Otherwise I get:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_LogFileManager", referenced from:
objc-class-ref in Logger.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 exactly am I missing here?
CocoaLumberjack is added via Carthage 3.2.0 for Xcode 8.
I've added the CocoaLumberjack.framework to the Build Phases like all the other frameworks in the project with /usr/local/bin/carthage copy-frameworks
Okay, I solved it. That error was very confusing but has nothing to do with anything. Sorry for that.
It is a big project with lots of build targets and lots of compile flags that make different things throw a warning and warnings become an error. In this case I added flags to disable the global ones to the mentioned Logger.m class. But I only added those anti-flags to one target and forgot to add them to another. That's why it didn't build.
Still strange, that the compiler didn't simply say: cannot build target A or compile error in file B. Instead I got a missing architecture message that was misleading me totally... So sorry for the trouble. Fixed it.

When I use NSPasteboard I met Undefined symbols for architecture x86_64 [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
symbol(s) not found in XCode, Cocoa application
Below is the error information
Undefined symbols for architecture x86_64:
"_NSPasteboardTypeString", referenced from:
_main in main.o
"_OBJC_CLASS_$_NSPasteboard", referenced from:
objc-class-ref in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
below is the code. Should I include more header?
#import <Foundation/Foundation.h>
#import <AppKit/NSPasteboard.h>
int main (int argc, const char * argv[])
{
#autoreleasepool {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSString *content = [pasteboard stringForType:NSPasteboardTypeString];
NSLog(#"%#", content);
}
return 0;
}
correctly link against AppKit.framework, headers dont contain the 'real' code

Hpple Error - "_OBJC_CLASS_$_TFHpple"

My app uses Hpple. I've included, TFHpple.h, TFHpple.m, TFHppleElement.h, TFHppleElement.m, XPathQuery.h & XPathQuery.m. Also included ${SDKROOT}/usr/include/libxml2 and -lxml2.
I have this tiny bit of code:
NSData *data = [[NSData alloc] initWithContentsOfFile:#"example.html"];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:data];
When I try to run it, I receive this error:
"_OBJC_CLASS_$_TFHpple", referenced from:
objc-class-ref in test.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I don't know how to solve this. Any ideas?
What exactly do you mean by "I've included" those files? The error indicates that you didn't add TFHpple.m to your target's "Compile Sources" build phase.

Weird Error With Apple Script Bridge - iTunes

I'm trying to create an ObjC application that will control iTunes. I need a method that will return an array of all the playlists in iTunes.
I'm getting the most bizarre, unhelpful error message ever... First the code:
#import "MusicControl.h"
#import "iTunes.h"
#implementation MusicControl
- (SBElementArray *) playlists {
// Create iTunes Object
iTunesApplication *iTunes = [SBApplication applicationWithBundleIdentifier:#"com.apple.iTunes"];
NSArray *sources = [iTunes sources];
iTunesSource *librarySource = nil;
for (iTunesSource *source in sources) {
if ([source kind] == iTunesESrcLibrary) {
librarySource = source;
break;
}
}
return [librarySource userPlaylists];
}
#end
I have no idea whether the array return is working or not because, after doing some debugging, I found that where this is bombing out is the very first line where I create the iTunes object, which was copied and pasted from Apple's website...
The error I'm getting is:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_SBApplication", referenced from:
objc-class-ref in MusicControl.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any suggestion as the what the heck is going on?
This message (and similar ones) means that the linker is looking for some specific symbol, but can't find it. In your case it is SBApplication.
If you have not already done so, you should make sure that you have linked to the ScriptingBridge framework.
To add a framework, click on the project's icon at the top of the left hand bar in Xcode, then select Build Phases. If Link With Binary Libraries is not already expanded, do that and add the framework.
The same procedure can be used for plain libraries (a framework is really just a wrapper around a library, at least for the purpose of this discussion).

Link error while accessing NSSpeechSynthesizer

I'm trying to compile a trivial command-line tool with XCode:
#import <Cocoa/Cocoa.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
//NSSpeechSynthesizer *speeker = [[NSSpeechSynthesizer alloc] initWithVoice: nil];
NSLog(#"%#", [NSSpeechSynthesizer availableVoices]);
NSLog(#"Hello, World!");
[pool drain];
return 0;
}
and even thought I'm importing Cocoa.h, I'm getting a link error:
Undefined symbols:
"_OBJC_CLASS_$_NSSpeechSynthesizer",
referenced from:
objc-class-ref-to-NSSpeechSynthesizer
in byc.o ld: symbol(s) not found
collect2: ld returned 1 exit status
Anybody knows what's going on???
You imported the header, so compilation worked, but linking failed because you didn't link against a framework that provides NSSpeechSynthesizer. You need to link against either the Application Kit framework (in addition to Foundation) or the Cocoa umbrella framework (instead of Foundation).
Whichever framework you choose, add it to your Linked Frameworks group in your project's group tree (by right-clicking on the group and choosing “Add Existing Framework”), and make sure you also add it to your target.