_OBJC_IVAR_$_Answer.answer" - objective-c

I have a class that holds number ivars:
// Answer.h
#import <Foundation/Foundation.h>
#interface Answer : NSObject{
#public
int firstNumber;
int secondNumber;
char myOperator;
}
#end
I try to access the code here
numberGroup->firstNumber = arc4random() % 1;
numberGroup->secondNumber = arc4random() % 10;
numberGroup->myOperator = arc4random() % 4;
and I get this error:
Ld
/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator/PowerBuilders.app/PowerBuilders
normal i386
cd "/Users/jack/Desktop/Xcode/Assorted Apps/PowerBuilders"
setenv MACOSX_DEPLOYMENT_TARGET 10.6
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/iPhoneSimulator5.1.sdk
-L/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator
-F/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator
-filelist /Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Intermediates/PowerBuilders.build/Debug-iphonesimulator/PowerBuilders.build/Objects-normal/i386/PowerBuilders.LinkFileList
-mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -Xlinker -no_implicit_dylibs -D__IPHONE_OS_VERSION_MIN_REQUIRED=50100 -framework UIKit -framework Foundation -framework CoreGraphics -o
/Users/jack/Library/Developer/Xcode/DerivedData/PowerBuilders-emehzkfcgntrhofxhvurovjmnugn/Build/Products/Debug-iphonesimulator/PowerBuilders.app/PowerBuilders
Undefined symbols for architecture i386:
"_OBJC_IVAR_$_Answer.firstNumber", referenced from:
-[ViewController lesson1] in ViewController.o "_OBJC_IVAR_$_Answer.myOperator", referenced from:
-[ViewController lesson1] in ViewController.o "_OBJC_IVAR_$_Answer.secondNumber", referenced from:
-[ViewController lesson1] in ViewController.o ld: symbol(s) not found for architecture i386 clang: error: linker command failed with
exit code 1 (use -v to see invocation)

The compiler generates symbol _OBJC_IVAR_$_Answer.firstNumber in the data segment as part of the Answer class metadata when it processes the #implementation section for the Answer class. The data at that symbol is the offset of the firstNumber instance variable within an Answer object.
Either you aren't linking your app with a file that contains an #implementation Answer section, or the compiler hasn't seen the declaration of the firstNumber instance variable before it sees the #implementation Answer section. Check that these are all true:
Answer.m is included in your target's Compile Sources phase.
Answer.m contains an #implementation Answer section.
Answer.m imports Answer.h at the top of Answer.m.

Related

Link with GNUstep on Ubuntu 14.04, 64 bit

I am attempting to compile a simple application that references GNUstep classes, with GNUstep on my Ubuntu 14.04, 64 bit, machine:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main(int argc, char **argv)
{
NSString *bestType = [[NSPasteboard generalPasteboard]
availableTypeFromArray: nil];
NSLog(#"best type: %#", bestType);
return 0;
}
Here are my compile and link flags (some of which may be overkill):
CFLAGS=`gnustep-config --objc-flags` -std=gnu99
LDFLAGS=`gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL
Before compilation I ran the script:
/usr/share/GNUstep/Makefiles/GNUstep.sh
And here is the output from 'make -n'
gcc main.m `gnustep-config --objc-flags` -std=gnu99 -L. `gnustep-config --base-libs` -lgnustep-base -lobjc -lm -lglut -lGLU -lGL -o tester
But when linking, Cocoa classes seem to not be pulled in, and I get an undefined reference error:
/tmp/ccnyXBoH.o:(.data.rel+0x8): undefined reference to `__objc_class_name_NSPasteboard'
If I remove all references to Cocoa classes in main.m, the app compiles without error.
The reason why you can't find the class definition for NSPasteboard is because it's in the gnustep-config --gui-libs options - i.e. the symbol is in the gui library of GNUStep, not in the base library of GNUStep. The solution is to change the LDFLAGS line to:
LDFLAGS=`gnustep-config --gui-libs` -lglut -lGLU -lGL
You shouldn't need to double-specify -lgnustep-base -lobjc -lm - they're part of both --base-libs and --gui-libs.

Undefined symbols for architecture x86_64: after adding an extension target to a react-native project

I created a react-native project using react-native init
I then add an action extension to that project using File -> new -> target -> Action Extension, with the name "Stash"
I try adding a StashView that inherits from UIView, and contains an RCTRootView, as instructed in the Integration with Existing App instructions:
Stash/StashView.h:
#import <UIKit/UIKit.h>
#interface StashView : UIView
#end
Stash/StashView.m:
#import "StashView.h"
#import "RCTRootView.h"
#implementation StashView
- (void)awakeFromNib {
NSString *urlString = #"http://localhost:8081/stash.ios.bundle";
NSURL *jsCodeLocation = [NSURL URLWithString:urlString];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName: #"Stash"
launchOptions:nil];
[self addSubview:rootView];
rootView.frame = self.bounds;
}
#end
When I compile, I get the error:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_RCTRootView", referenced from:
objc-class-ref in StashView.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code
1 (use -v to see invocation)
The full stack trace:
Ld
/Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Products/Debug-iphonesimulator/Stash.appex/Stash
normal x86_64
cd /Users/danoved/Source/myprojects/ToDoBox
export IPHONEOS_DEPLOYMENT_TARGET=8.1
export 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 x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk
-L/Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Products/Debug-iphonesimulator
-F/Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Products/Debug-iphonesimulator
-filelist /Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Intermediates/ToDoBox.build/Debug-iphonesimulator/Stash.build/Objects-normal/x86_64/Stash.LinkFileList
-Xlinker -rpath -Xlinker #executable_path/Frameworks -Xlinker -rpath -Xlinker #executable_path/../../Frameworks -Xlinker -objc_abi_version -Xlinker 2 -OjbC /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/System/Library/PrivateFrameworks/PlugInKit.framework/PlugInKit -e _NSExtensionMain -fobjc-arc -fobjc-link-runtime -fapplication-extension -Xlinker -no_implicit_dylibs -mios-simulator-version-min=8.1 -Xlinker -dependency_info -Xlinker /Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Intermediates/ToDoBox.build/Debug-iphonesimulator/Stash.build/Objects-normal/x86_64/Stash_dependency_info.dat
-o /Users/danoved/Library/Developer/Xcode/DerivedData/ToDoBox-gmtanlmumdrkqactpypioaempcuc/Build/Products/Debug-iphonesimulator/Stash.appex/Stash
What am I doing wrong? Something in the build settings?
Figured it out!
Based on the answer here
I had to open the Link Binary with Libraries carrot in the Build Phases of the extension, and add all of the react libraries to it:

Why did the HelloWorld codes using cocoa's library fail to build?

The codes are like this:
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[])
{
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
}
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:#"Hi there."];
[alert runModal];
return 0;
}
What I want is: when called from command line, this program pops up an alert box, when I close the alertbox. The program exits.
But when building, it complains like this:
Ld /Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Products/Debug/KeyCatcher normal x86_64
cd /Users/hanfei/Desktop/KeyCatcher
setenv MACOSX_DEPLOYMENT_TARGET 10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk -L/Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Products/Debug -F/Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Products/Debug -filelist /Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Intermediates/KeyCatcher.build/Debug/KeyCatcher.build/Objects-normal/x86_64/KeyCatcher.LinkFileList -mmacosx-version-min=10.9 -fobjc-arc -fobjc-link-runtime -framework Foundation -Xlinker -dependency_info -Xlinker /Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Intermediates/KeyCatcher.build/Debug/KeyCatcher.build/Objects-normal/x86_64/KeyCatcher_dependency_info.dat -o /Users/hanfei/Library/Developer/Xcode/DerivedData/KeyCatcher-hijnrqhwiafuxtdjmdubtsijyhwh/Build/Products/Debug/KeyCatcher
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$_NSAlert", 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)
When I choose the template for new project, I select command line tool instead of CoCoa Application as I just need CoCoa to display an alertbox. Does anyone have ideas about this..
That's because NSAlert is not #imported.
AppKit.h is not included by default when you create a command line tool , as you can see in the link, AppKit imports NSAlert.h.
EDIT:
First, to compile you need to add the Cocoa framework in your project.
Second, all the code should be enclosed in the #autoreleasepool section
#autoreleasepool {
// insert code here...
NSLog(#"Hello, World!");
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:#"Hi there."];
[alert runModal];
}
Your code will compile and run, but I think you'll have some other runtime errors.
I got the same error in C++ project that was using a NSAlert, this worked for me:
1) Adding
#include <Cocoa/Cocoa.h>
2) Adding Cocoa Framework in project->Buld Phases->Link Binary With Libraries.
3) Setting "Type" of all my .cpp files to "Objective-C++ Source" in the most right column in xCode.
you need to add this before main function
#import <AppKit/AppKit.h>
You need to import AppKit as mentioned by others and – as important as the framework – you need a run loop. So insert before the runModal line
[NSApplication sharedApplication];
to launch the "application" and the run loop

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

Try to integrate LinkedIn in iPhone application

I have download the source from https://github.com/ResultsDirect/LinkedIn-iPhone . Demo working fine, and try to use in my application.
I have followed all the steps already whatever required as mention here in post ...
But I have getting the error
"_OBJC_CLASS_$_RDLinkedInEngine", referenced from:
"_OBJC_CLASS_$_RDLinkedInAuthorizationController", referenced from:
When I comment the lines of RDLinkedInEngine and RDLinkedInAuthorizationController then error are removed
- (void)loadView {
[super loadView];
// rdEngine = [[RDLinkedInEngine engineWithConsumerKey:kOAuthConsumerKey consumerSecret:kOAuthConsumerSecret delegate:self] retain];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
// if( !rdHasAppeared ) {
// UIViewController* controller = [RDLinkedInAuthorizationController authorizationControllerWithEngine:rdEngine delegate:self];
// if( controller ) {
// [self presentModalViewController:controller animated:YES];
// rdHasAppeared = YES;
// }
// else {
// NSLog(#"Already authenticated");
// }
// }
}
I my application I have already integrated MGTwitterEngine from source https://github.com/bengottlieb/Twitter-OAuth-iPhone Which is wokring ok.
Amit Battan
most probably you need to add some static library (.a file)... or src folder itself from linkedIn source...
I have gone through the same issue. It can be solved by setting Library Dependency. Select project target and then select general. There you will find Direct dependencies. Add LinkedInLibrary from LinkedInClientLibrary.xcodeProject
#mihir
Build butterfli of project butterfli with configuration Debug
CompileC build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfliViewController.o /Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m normal i386 objective-c com.apple.compilers.gcc.4_2
cd /Users/pratgupta/Desktop/butterfli
setenv LANG en_US.US-ASCII
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -x objective-c -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -fexceptions -fvisibility=hidden -mmacosx-version-min=10.6 -gdwarf-2 -fobjc-abi-version=2 -fobjc-legacy-dispatch -D__IPHONE_OS_VERSION_MIN_REQUIRED=40100 -iquote /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-generated-files.hmap -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-own-target-headers.hmap -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-all-target-headers.hmap -iquote /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/butterfli-project-headers.hmap -F/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator -iquote/Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary -I/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator/include -I/Users/pratgupta/Desktop/butterfli/OAuthConsumeriPhoneLib -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/usr/include/libxml2 -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/DerivedSources/i386 -I/Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/DerivedSources -include /var/folders/RE/RE2wCP+eEqaZg4J2Og3nmE+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/butterfli_Prefix-aeetprdcvcynktfkafjmijthtlhp/butterfli_Prefix.pch -c /Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m -o /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfliViewController.o
/Users/pratgupta/Desktop/butterfli/Classes/butterfliViewController.m:321: warning: property 'fbPermissions' requires method '-fbPermissions' to be defined - use #synthesize, #dynamic or provide a method implementation
Ld build/Debug-iphonesimulator/butterfli.app/butterfli normal i386
cd /Users/pratgupta/Desktop/butterfli
setenv MACOSX_DEPLOYMENT_TARGET 10.6
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator "-L/Users/pratgupta/Desktop/butterfli/Twitter+OAuth/Libraries & Headers" -F/Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator -filelist /Users/pratgupta/Desktop/butterfli/build/butterfli.build/Debug-iphonesimulator/butterfli.build/Objects-normal/i386/butterfli.LinkFileList -mmacosx-version-min=10.6 -all_load -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -lOAuth -lxml2 /Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary/build/Debug-iphonesimulator/libLinkedInClientLibrary.a -o /Users/pratgupta/Desktop/butterfli/build/Debug-iphonesimulator/butterfli.app/butterfli
ld: duplicate symbol _EstimateBas64EncodedDataSize in /Users/pratgupta/Desktop/butterfli/LinkedInClientLibrary/build/Debug-iphonesimulator/libLinkedInClientLibrary.a(Base64Transcoder.o) and /Users/pratgupta/Desktop/butterfli/Twitter+OAuth/Libraries & Headers/libOAuth.a(Base64Transcoder.o)
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1