Linker error when use Json to parse the string - objective-c

I am trying to use JSON to parse the sting that i have got from ASIHttpRequest but i find linker error e.g.
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_SBJsonParser", referenced from:
objc-class-ref in AppDelegate.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation
Below is the code that i am using.For more detail i have already added Json classes in the project.
(void)requestFinished:(ASIHTTPRequest *)request{
// Use when fetching text data
NSString *responseString = [request responseString];
SBJsonParser *parser=[[SBJsonParser alloc]init ];
NSDictionary *obj=[parser objectWithString:responseString error:NULL];
NSArray *list=[obj objectForKey:#"lessons"];
// Use when fetching binary data
// NSData *responseData = [request responseData];
}

From the search i found that we have to include the .m Json files in the compile source. We can do this by click on the project->Target->Build Phase->compile source->add the all the json .m files

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.

Crash with SBJSON library

following code is copied from Stig Brautaset JSON library - I removed the comments to be more clear.
#interface NSString (NSString_SBJSON)
- (id)JSONFragmentValue;
- (id)JSONValue;
#end
I have a crash when I call:
NSString *jsonString = [request responseString];
...
NSDictionary *results = [jsonString JSONValue];//here is the crash with invalid selector.
I added this:
if (![jsonString respondsToSelector:#selector(JSONValue)])
{
NSLog(#"fix this!!!\n");
}
and the message is shown. Do you have any idea why this function in not called?
Thanks!
EDIT: I compile JSON framework as a static lib. The call is made in the same lib.
When I compile it as exe it runs without any problem.
You need to both link your static library and your final executable with the -ObjC linker option.
The -JSONValue method is implemented as a category on the NSString class in the file NSString+SBJSON.m file. Because of how the dynamic runtime works in Objective-C, categories defined in static libraries don't get loaded up unless you link with the -Objc flag. If the category doesn't get loaded, then dynamic binding fails, and you get the dreaded "doesn't respond to selector" exception.

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.