Is possible to use CATextLayer in a c struct? - objective-c

I need to associate a tag with a CATextLayer so I thought this:
.h
#import <QuartzCore/QuartzCore.h>
#import <CoreText/CoreText.h>
typedef struct textLayerWithTag
{
CATextLayer *textLayer;
int tag;
}textLayerWithTag;
.m`
textLayerWithTag textLayer1;
textLayer1.tag = 0;
textLayer1.textLayer = [[CATextLayer alloc] init];
textLayer1.textLayer.string = #"aaaa";
textLayer1.textLayer.frame = CGRectMake(0.f, 10.f, 320.f, 32.f);
[self.view.layer addSublayer:textLayer1.textLayer];`
But when I try to build it I have this error:
"_OBJC_CLASS_$_CATextLayer", referenced from:
objc-class-ref-to-CATextLayer in StructViewController.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Any ideas? :/

You probably aren't linking the QuartzCore and CoreText Frameworks to your project. Right click on the Frameworks Group in XCode and then do add->Existing Frameworks... Select QuartzCore and CoreText and you should be good to go!

Related

Open offline jpg-images in a command-line-application in Objective-C under Mac OS X 10.6.8 and Xcode 3.2.6

What I do: I'm pretty new to Objective-C and I write an command-line-application on my old Macbook 2,1 that works with pictures.
My problem: I just want to get the width and height as a number (int, NSInteger, NSNumber, …) of a picture saved on my local hard-drive „Macintosh HD“.
Relevance for others: There must be a programatical way, to work with pictures. This is pretty basic.
My work platform: I'm developing on Mac OS X 10.6.8 with Xcode 3.2.6.
My research history: I already looked for cook-book-recipies and background-knowledge at stackoverflow and a few other sites to make my following trials, but I wasn't successful, yet. I present all I tried in the following. In advance, nothing worked.
//BildOeffner.h:
#import <Cocoa/Cocoa.h>
#interface BildOeffner : NSView
-(BildOeffner*) init;
- (NSNumber*) extrahiereBildBreite:(NSString*) bildPfad;
#end
//BildOeffner.m:
#import "BildOeffner.h"
#implementation BildOeffner
// extracts the image width
- (NSNumber*) extrahiereBildBreite:(NSString*) bildPfad{
NSBitmapImageRep* nsImageRep = [NSBitmapImageRep imageRepWithContentsOfFile:bildPfad];
NSInteger extrahierteBildBreite =[nsImageRep pixelsWide];
NSNumber* bildBreite = [NSNumber numberWithInt:extrahierteBildBreite];
return bildBreite;
}
#end
The code shows no compile-errors in the editor, but there are errors in the build-results: The Error-Message:
Ld build/Debug/FotobuchErsteller_0 normal x86_64
cd /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/gcc-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug -F/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug -filelist /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/Objects-normal/x86_64/FotobuchErsteller_0.LinkFileList -mmacosx-version-min=10.6 -framework Foundation -o /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug/FotobuchErsteller_0
Undefined symbols:
"_OBJC_CLASS_$_NSImage", referenced from:
objc-class-ref-to-NSImage in BildOeffner.o
"_OBJC_METACLASS_$_NSView", referenced from:
_OBJC_METACLASS_$_BildOeffner in BildOeffner.o
"_OBJC_CLASS_$_NSView", referenced from:
_OBJC_CLASS_$_BildOeffner in BildOeffner.o
"_OBJC_CLASS_$_NSBitmapImageRep", referenced from:
objc-class-ref-to-NSBitmapImageRep in BildOeffner.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
then I tried the following:
//BildAnalyst.h:
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#interface BildAnalyst : NSObject
#property (assign) NSArray* bilderListe;
#property (assign) NSArray* bildObjektListe;
#property (assign) NSNumber* erwarteteBildHoehe;
#property (assign) NSNumber* erwarteteBildBreite;
-(BildAnalyst*) init;
-(BildAnalyst*) initWith:(NSArray*) neueBilderListe;
- (NSArray *)bilderListe;
- (void)setBilderListe:(NSArray *) neueBilderListe;
- (NSArray *)bildObjektListe;
- (void)setBildObjektListe:(NSArray *) neueBildObjektListe;
- (NSNumber*)erwarteteBildHoehe;
- (void)setErwarteteBildHoehe:(NSNumber*) neueErwarteteBildHoehe;
- (NSNumber*)erwarteteBildBreite;
- (void)setErwarteteBildBreite:(NSNumber*) neueErwarteteBildBreite;
- (void) erstelleListeAllerBilderImOrdner:(NSString*) absoluterPfadZumOrdner;
- (void) analysiereBilderListe;
#end
//BildAnalyst.m:
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import "BildAnalyst.h"
#import "Bild.h"
#implementation BildAnalyst
- (id)init {
self = [super init];
if (self){
self.bilderListe = nil;
self.erwarteteBildHoehe = [NSNumber numberWithInt:3024];
self.erwarteteBildBreite = [NSNumber numberWithInt:4032];
}
return self;
}
/*Der explizite Konstruktor dieser Klasse.
Parameter: NSMutableArray neueBilderListe
Rueckgabe: BildAnalyst bildAnalyst*/
-(BildAnalyst*) initWith:(NSMutableArray*) neueBilderListe{
self = [super init];
if (self){
self.bilderListe = neueBilderListe;
}
return self;
}
- (void) setBilderListe:(NSArray *) neueBilderListe{
self.bilderListe = neueBilderListe;
}
- (NSArray *) bilderListe{
return self.bilderListe;
}
- (void)setBildObjektListe:(NSArray *) neueBildObjektListe{
self.bildObjektListe = neueBildObjektListe;
}
- (NSArray *)bildObjektListe{
return self.bildObjektListe;
}
- (NSNumber*)erwarteteBildHoehe{
return self.erwarteteBildHoehe;
}
- (void)setErwarteteBildHoehe:(NSNumber*) neueErwarteteBildHoehe{
self.erwarteteBildHoehe = neueErwarteteBildHoehe;
}
- (NSNumber*)erwarteteBildBreite{
return self.erwarteteBildBreite;
}
- (void)setErwarteteBildBreite:(NSNumber*) neueErwarteteBildBreite{
self.erwarteteBildBreite = neueErwarteteBildBreite;
}
/* Die folgende Methode dient dem Auslesen eines Ordners und dem Speichern von darin enthaltenen Objekten in erster Hierarchieebene in ein Array, welches die Instanzvariable "bilderListe" befuellt.
Parameter NSString* absoluterPfadZumOrdner*/
- (void) erstelleListeAllerBilderImOrdner:(NSString*) absoluterPfadZumOrdner{
NSError* fehlerBeimLesenDesBilderordners;
NSFileManager* nsFileManager = [NSFileManager defaultManager];
[nsFileManager changeCurrentDirectoryPath:absoluterPfadZumOrdner];
NSArray* dateiListe = [nsFileManager contentsOfDirectoryAtPath:absoluterPfadZumOrdner error:&fehlerBeimLesenDesBilderordners];
[self setBilderListe:dateiListe];
}
/*Die folgende Methode dient der Analyse der Bilder, welche in einem Ordner gefunden wurden. Sie bestimmt das Bildformat und speichert die Bilder als Objekte in die Instanzvariable "bildObjektListe".
Parameter NSArray bilderListe*/
- (void) analysiereBilderListe {
NSUInteger i, count = [[self bilderListe] count];
NSMutableArray* neueBildObjektListe = [[NSMutableArray alloc] init];
for (i = 0; i < count; i++) {
NSString* bildPfad = [[self bilderListe] objectAtIndex:i];
NSBitmapImageRep* nsImageRep = [NSBitmapImageRep imageRepWithContentsOfFile:bildPfad];
NSInteger extrahierteBildHoehe = [nsImageRep pixelsHigh];
NSNumber* bildHoehe = [NSNumber numberWithInt:extrahierteBildHoehe];
NSInteger extrahierteBildBreite =[nsImageRep pixelsWide];
NSNumber* bildBreite = [NSNumber numberWithInt:extrahierteBildBreite];
Bild* bild = [[Bild alloc] init];
[bild setVollstaendigerBildName:bildPfad];
if ((bildHoehe == self.erwarteteBildHoehe) && (bildBreite == self.erwarteteBildBreite)) {
[bild setBildformat:hochformat];
} else if ((bildHoehe == self.erwarteteBildBreite) && (bildBreite == self.erwarteteBildHoehe)) {
[bild setBildformat:querformat];
} else if (bildHoehe ==bildBreite){
[bild setBildformat:quadratisch];
} else {
continue;
}
[neueBildObjektListe insertObject:bild atIndex:i];
}
self.bildObjektListe = neueBildObjektListe;
}
#end
with the class „Bild“:
//Bild.h:
#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
typedef enum {hochformat, quadratisch, querformat} Bildformat;
#interface Bild : NSObject
#property (assign) NSString *vollstaendigerBildName;
#property (assign) Bildformat bildformat;
- (Bild*)init;
- (Bild*)init:(NSString *) bildName nunDasBildformat:(Bildformat)dasBildFormat;
- (void)setVollstaendigerBildName:(NSString *) neuerVollstaendigerBildName;
- (NSString *)vollstaendigerBildName;
- (void)setBildformat:(Bildformat) neuesBildformat;
- (Bildformat)bildformat;
#end
//Bild.m:
#import "Bild.h"
#implementation Bild
- (Bild*)init {
self = [super init];
if (self){
self.vollstaendigerBildName = #"";
self.bildformat = hochformat;
}
return self;
}
/*Der explizite Konstruktor dieser Klasse.
Parameter NSString bildName
Parameter Bildformat dasBildFormat
Rueckgabe Bild bild*/
- (Bild*)init:(NSString *)bildName nunDasBildformat:(Bildformat)dasBildFormat {
self = [super init];
if (self){
self.vollstaendigerBildName = bildName;
self.bildformat = dasBildFormat;
}
return self;
}
- (void) setVollstaendigerBildName:(NSString *) neuerVollstaendigerBildName{
self.vollstaendigerBildName = neuerVollstaendigerBildName;
}
- (NSString *) vollstaendigerBildName{
return self.vollstaendigerBildName;
}
- (void)setBildformat:(Bildformat) neuesBildformat{
self.bildformat = neuesBildformat;
}
- (Bildformat)bildformat{
return self.bildformat;
}
#end
The code shows no compile-errors in the editor, but there are errors in the build-results: The error-Message:
Ld build/Debug/FotobuchErsteller_0 normal x86_64
cd /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/gcc-4.2 -arch x86_64
-isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug
-F/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug
-filelist /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/Objects-normal/x86_64/FotobuchErsteller_0.LinkFileList -mmacosx-version-min=10.6
-framework Foundation -o /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug/FotobuchErsteller_0
Undefined symbols:
"_OBJC_CLASS_$_NSBitmapImageRep", referenced from:
objc-class-ref-to-NSBitmapImageRep in BildAnalyst.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
then I tried the following with the same class „BildAnalyst“:
I used
NSURL* nsUrl = [NSURL fileURLWithPath:bildPfad];
CIImage* nsImageRep = [CIImage imageWithContentsOfURL:nsUrl];
instead of
NSBitmapImageRep* nsImageRep = [NSBitmapImageRep imageRepWithContentsOfFile:bildPfad];
The code shows no compile-errors in the editor, but there are errors in the build-results: the error-Message:
Ld build/Debug/FotobuchErsteller_0 normal x86_64
cd /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0
setenv MACOSX_DEPLOYMENT_TARGET 10.6
/Developer/usr/bin/gcc-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug -F/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug -filelist /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/Objects-normal/x86_64/FotobuchErsteller_0.LinkFileList -mmacosx-version-min=10.6 -framework Foundation -o /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug/FotobuchErsteller_0
Undefined symbols:
"_OBJC_CLASS_$_CIImage", referenced from:
objc-class-ref-to-CIImage in BildAnalyst.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
then I tried the following with the same class „BildAnalyst“:
I used
NSURL* nsUrl = [NSURL fileURLWithPath:bildPfad];
NSData* nsData = [NSData dataWithContentsOfURL:nsUrl];
UIImage* nsImageRep = [UIImage imageWithData:nsData];
instead of
NSBitmapImageRep* nsImageRep = [NSBitmapImageRep imageRepWithContentsOfFile:bildPfad];
The code shows compile-errors at the line with UIImage. The error-Messages:
CompileC build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/Objects-normal/x86_64/BildAnalyst.o BildAnalyst.m normal x86_64 objective-c com.apple.compilers.gcc.4_2
cd /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0
setenv LANG en_US.US-ASCII
/Developer/usr/bin/gcc-4.2 -x objective-c -arch x86_64 -fmessage-length=0 -pipe -std=gnu99
-Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.6.sdk -mfix-and-continue -mmacosx-version-min=10.6 -gdwarf-2
-iquote /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/FotobuchErsteller_0-generated-files.hmap
-I/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/FotobuchErsteller_0-own-target-headers.hmap
-I/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/FotobuchErsteller_0-all-target-headers.hmap -iquote /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/FotobuchErsteller_0-project-headers.hmap
-F/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug
-I/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/Debug/include
-I/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/DerivedSources/x86_64
-I/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/DerivedSources -include /var/folders/1J/1J8zfhnuH3Gk3T++j4sPBE+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/FotobuchErsteller_0_Prefix-gqjmlqmlzpuhpyfvtxjjyzqdlikg/FotobuchErsteller_0_Prefix.pch
-c /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m
-o /Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/build/FotobuchErsteller_0.build/Debug/FotobuchErsteller_0.build/Objects-normal/x86_64/BildAnalyst.o
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m: In function '-[BildAnalyst analysiereBilderListe]':
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:112: error: 'UIImage' undeclared (first use in this function)
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:112: error: (Each undeclared identifier is reported only once
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:112: error: for each function it appears in.)
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:112: error: 'nsImageRep' undeclared (first use in this function)
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:113: warning: unused variable 'bildHoehe'
/Users/Edo/Documents/FotobuchSkriptErsteller/FotobuchSkriptErsteller/FotobuchErsteller_0/BildAnalyst.m:104: warning:
unused variable 'neueBildObjektListe'
{standard input}:unknown:Undefined local symbol L_OBJC_CLASSLIST_SUP_REFS_$_0
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_0
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_1
{standard input}:unknown:Undefined local symbol L_OBJC_CLASSLIST_REFERENCES_$_1
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_2
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_3
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_4
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_5
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_6
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_7
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_8
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_9
{standard input}:unknown:Undefined local symbol L_OBJC_CLASSLIST_REFERENCES_$_2
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_10
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_11
{standard input}:unknown:Undefined local symbol L_OBJC_SELECTOR_REFERENCES_12
Has anybody a suggestion, what I can improve or perhaps another way? I just want to get the width and height of a picture saved on my local hard-drive „Macintosh HD“ as a number (int, NSInteger, NSNumber, ...).
Command-line tools, by default, link only against Foundation. You need to make sure your project is linked against the AppKit framework (or Cocoa, which automatically links to both Foundation or AppKit). Select your project in Xcode, select your target, and click on the "Build Phases" tab. In "Link Binary With Libraries", add AppKit. You should have access to AppKit classes such as NSImage.

readline in objective-c program throwing Mach-O Linker (Id) Error

When I try to run the following code, xcode throws the following error. What is causing this?
#import <Foundation/Foundation.h>
#include <readline/readline.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
NSLog(#"What number would you like to count down by three from?");
const char *countFrom = readline(NULL);
NSString *result = [NSString stringWithUTF8String:countFrom];
NSLog(#"Counting down from %#", result);
}
return 0;
}
Undefined symbols for architecture x86_64:
"_readline", referenced from:
_main 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)
Figured it out. Had to go into the Link Binary With Libraries section in the Build Phases section of project settings and include libreadline.dylib.

Apple Mach-0 linker error duplicate

I have written a straight forward program, but getting duplicate symbol linker error (error below) There is nothing additional in the .h file excepting for the #interface Fraction : NSObject #end
I am rather new to xcode.
//SAMPLE CODE
#import "JTViewController.h"
#interface Fraction ()
-(void) print;
-(void) setNumerator: (int) n;
-(void) setDenominator: (int) d;
#end
#implementation Fraction
{
int numerator;
int denominator;
}
-(void) print
{
NSLog (#"%i/%i", numerator, denominator);
}
-(void) setNumerator:(int)n
{
numerator = n;
}
-(void) setDenominator:(int)d
{
denominator = d;
}
#end
int main (int argc, char * argv[])
{
#autoreleasepool {
// Create an instance of Fraction and initialise it
Fraction *myFraction = [[Fraction alloc] init];
//Set Fraction to 1/3
[myFraction setNumerator: 1];
[myFraction setDenominator: 3];
//Display the fraction using the print method
[myFraction print];
}
return 0;
}
This is the error
Ld /Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Products/Debug-iphonesimulator/BrandNew.app/BrandNew normal i386
cd /Users/jamesmurray/AppsDev/BrandNew
setenv IPHONEOS_DEPLOYMENT_TARGET 6.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Products/Debug-iphonesimulator -F/Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Products/Debug-iphonesimulator -filelist /Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Intermediates/BrandNew.build/Debug-iphonesimulator/BrandNew.build/Objects-normal/i386/BrandNew.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=6.1 -framework UIKit -framework Foundation -framework CoreGraphics -o /Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Products/Debug-iphonesimulator/BrandNew.app/BrandNew
duplicate symbol _main in:
/Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Intermediates/BrandNew.build/Debug-iphonesimulator/BrandNew.build/Objects-normal/i386/main.o
/Users/jamesmurray/Library/Developer/Xcode/DerivedData/BrandNew-akqlirretjwoeuaqkrwlbqmlqxlc/Build/Intermediates/BrandNew.build/Debug-iphonesimulator/BrandNew.build/Objects-normal/i386/JTViewController.o
ld: 1 duplicate symbol for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have no idea where it came from. Any assistance would be appreciated.
Like the linker error says, you have two main() functions; one in main.m and one in JTViewController.m.
Remove the one in JTViewController.m (move the functionality into main.m).
There is nothing special about main here. You can only have one globally visible non-common symbol in your object files. Non-static functions are globally visible and non-common symbols, hence you can only have a function with a specific name defined only once. For example:
a.c:
int func() { ... }
b.c:
void func(int arg) { ... }
When both files are compiled, it creates two globally visible symbols with the name of func (with whatever decoration the compiler might apply to the symbol), despite the difference in the argument lists and the return types. As the linker tries to resolve all symbol references in order to produce the final executable, it faces the hard choice of selecting the right version of func, so it takes the most direct approach - simply gives you an error about duplicate symbol definition and bails out.
This is not a requirement unique to the C language (and Objective-C is basically a runtime extension of C) as it is imposed by the system linker. It also translates to many other languages like Objective-C, C++, Fortran, Pascal, etc. In C++ function symbols are decorated according to the namespace they live in and the list of their arguments (the former enables function overloading), but again one cannot have two functions with the same list of arguments in the same namespace defined in different source files.
Usually C and C++ functions are compiled to globally visible symbols unless the static modifier is applied:
a.c:
static int func() { ... }
b.c:
void func(int arg) { ... }
This would not result in a global symbol func in a.o clashing with the one in b.o and the linker would not complain. It would also work if rather func in b.c is given the static treatment or if both functions are static.

unrecognized selector sent to class when trying to create UIColor

I'm trying to create a custom color out of a hex color code. I have a seperate class called UIColor+Hex, that takes in a hex string and converts it to a color code and returs a UIColor.
UIColor+Hex.h
#import <UIKit/UIKit.h>
#interface UIColor (Hex)
+ (UIColor *)colorWithHexString:(NSString *)hex;
#end
UIColor+Hex.m
#import "UIColor+Hex.h"
#implementation UIColor (Hex)
+ (UIColor *)colorWithHexString:(NSString *)hex
{
if ([hex length]!=6 && [hex length]!=3)
{
return nil;
}
NSUInteger digits = [hex length]/3;
CGFloat maxValue = (digits==1)?15.0:255.0;
NSUInteger redHex = 0;
NSUInteger greenHex = 0;
NSUInteger blueHex = 0;
sscanf([[hex substringWithRange:NSMakeRange(0, digits)] UTF8String], "%x", &redHex);
sscanf([[hex substringWithRange:NSMakeRange(digits, digits)] UTF8String], "%x", &greenHex);
sscanf([[hex substringWithRange:NSMakeRange(2*digits, digits)] UTF8String], "%x", &blueHex);
CGFloat red = redHex/maxValue;
CGFloat green = greenHex/maxValue;
CGFloat blue = blueHex/maxValue;
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
#end
I then have UIColor+Hex.h imported to one of my other classes and make a call to it by:
[self setSelectedfillColor:[UIColor colorWithHexString:#"FF0000"].CGColor];
Whenever I hit this code I get this error...
'NSInvalidArgumentException', reason: '+[UIColor colorWithHexString:]: unrecognized selector sent to class 0x873d60'
I've tried everything I could think of but I still keep getting that error. Anyone have any ideas why this would be happening?
Add -ObjC -all_load to your Other Linker Flags in your project under the Build Settings.
-ObjC allow the static library to use objective-c specific stuffs like kvc or categories.
-all_load solve a bug in gcc/llvm, where -ObjC is not correctly used.
https://developer.apple.com/library/mac/#qa/qa2006/qa1490.html
Make sure to add UIColor+Hex.m to the Compile Sources list in the Build Phases tab.
The compiler doesn't complain during the build but dies on the selector at runtime.
All too often, it's the missing classes in "Compile Sources" in XCode.
Tested your category as you posted and it works fine even with the cgcolor property method. Separate those two lines and make sure the problem is not with setSelectedFillColor. Sometimes the debug errors can be misleading.

Xcode print symbol not found for my C function which used in Objective-C method body

Xcode build prints this error .
Undefined symbols:
"EGViewportDimensionMake(unsigned int,
unsigned int, unsigned int, unsigned
int)", referenced from:
-[Renderer render] in Renderer.o ld: symbol(s) not found collect2: ld
returned 1 exit status
I cannot figure out what's the problem. I'm not good at classic C syntax.
These are the function source code files:
EGViewportDimension.h
#import <Foundation/Foundation.h>
struct EGViewportDimension
{
NSUInteger x;
NSUInteger y;
NSUInteger width;
NSUInteger height;
};
typedef struct EGViewportDimension EGViewportDimension;
EGViewportDimension EGViewportDimensionMake(NSUInteger x, NSUInteger y, NSUInteger width, NSUInteger height);
EGViewportDimension.m
#import "EGViewportDimension.h"
EGViewportDimension EGViewportDimensionMake(NSUInteger x, NSUInteger y, NSUInteger width, NSUInteger height)
{
EGViewportDimension dim;
dim.x = x;
dim.y = y;
dim.width = width;
dim.height = height;
return dim;
}
I referenced and used this like:
Renderer.mm
#import "EGViewportDimension.h"
//.... many codes omitted.
EGViewportDimension vdim = EGViewportDimensionMake(0, 0, backingWidth, backingHeight);
This is not a compiler but a linker issue. You referenced this method from [Renderer render], however the linker is unable to find it. Did you check you have included EGViewportDimension.h at the appropriate place (eg. Renderer.m)?
I solved it by renaming Renderer.mm to Renderer.m.
It was used some C++ classes so I made it as Objective-C++ code, but there was some problem.
I removed all C++ calls and renamed it to Objective-C code.
But I still don't know what's the problem with Objective-C++ with classic C function definition.
----(edit)----
I asked this as another question, and I got an answer. See here:
Does it prohibited calling classic C function from Objective-C++ class method body?