2014-07-21 1 views
1

저는 OS 개발의 초보자입니다. 나는 몇 시간을 검색하고 많은 일을 시도하지만 여전히 일하지 않습니다. 나는 완전히 외롭다.전역 상수를 사용할 때 컴파일 된 오류 : "아키텍처 i386에 대한 정의되지 않은 기호"

2 개의 스토리 보드 (iPhone + iPad) 및 3 쌍의 파일 .h/.m (AppDelgate, MasterViewController, DetailViewController)이있는 프로젝트가 있습니다.

나는 내 AppDelegate.m에 필요한 모든를 다운로드하고 같이 내 AppDelegate.h에서 선언 된 전역 상수에 결과를 저장하고 싶습니다 : AppDelegate.m

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 
//javascript & css files 
extern NSData *const JQUERY_FILE; 
extern NSData *const JQUERYUI_FILE; 
extern NSData *const JQUERY_MOBILE_FILE; 
extern NSData *const JQUERY_MOBILE_CSS_FILE; 
extern NSData *const APPLICATION_FILE; 
extern NSData *const FEED_FILE; 
@end 

을 그리고 지역 :

#import "AppDelegate.h" 
@implementation AppDelegate 
    NSURL *url = [NSURL URLWithString:@"http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"]; 
    NSString *path = [NSString stringWithFormat:@"%@/Library/Application Support/jquery.js", NSHomeDirectory()]; 
    NSData *const JQUERY_FILE = [NSData dataWithContentsOfURL:url]; 
    [JQUERY_FILE writeToFile:path options:NSDataWritingAtomic error:&error]; 
… 
을 제 2 개 다른 사람 내가 AppDelegate.h을 가져

파일을하는 .m : MasterViewController.m & DetailViewController.m

내가 컴파일 오류 때이 내 프로젝트를 만들어보십시오. 내가 좋아하는 것

Ld /Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Products/Debug-iphonesimulator/Test_JSON_V2.app/Test_JSON_V2 normal i386 
cd /Users/Karine/Projects/Test_JSON_V2/IOS-ManualJson 
export IPHONEOS_DEPLOYMENT_TARGET=7.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 i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.1.sdk -L/Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Products/Debug-iphonesimulator -F/Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Products/Debug-iphonesimulator -filelist /Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Intermediates/Test_JSON_V2.build/Debug-iphonesimulator/Test_JSON_V2.build/Objects-normal/i386/Test_JSON_V2.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=7.1 -framework CoreGraphics -framework UIKit -framework Foundation -Xlinker -dependency_info -Xlinker /Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Intermediates/Test_JSON_V2.build/Debug-iphonesimulator/Test_JSON_V2.build/Objects-normal/i386/Test_JSON_V2_dependency_info.dat -o /Users/admin/Library/Developer/Xcode/DerivedData/Test_JSON_V2-avjvupkzamqjszcpvufoeqrdbjin/Build/Products/Debug-iphonesimulator/Test_JSON_V2.app/Test_JSON_V2 

    Undefined symbols for architecture i386: 
"_APPLICATION_FILE", referenced from: 
    -[MasterViewController viewDidLoad] in MasterViewController.o 
"_JQUERYUI_FILE", referenced from: 
    -[DetailViewController webViewDidFinishLoad:] in DetailViewController.o 
"_JQUERY_FILE", referenced from: 
    -[DetailViewController webViewDidFinishLoad:] in DetailViewController.o 
"_JQUERY_MOBILE_CSS_FILE", referenced from: 
    -[DetailViewController webViewDidFinishLoad:] in DetailViewController.o 
"_JQUERY_MOBILE_FILE", referenced from: 
    -[DetailViewController webViewDidFinishLoad:] in DetailViewController.o 
ld: symbol(s) not found for architecture i386 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

당신에게 PRINTSCREEN을 제공합니다하지만 난 너무 초보자이야 할 수 없기 때문에 다음에 내 3m 파일은 파일 편집기에서 대상 회원에 확인/

하고, 내가하려고 (빌드 단계에서) 소스 컴파일 : 모든 상수를 포함하는 .H 파일을 생성

  • 을하고 편집기를 수행하여 추가 -> 빌드 단계 추가 -> 추가 사본 헤더는
  • AppDelegate에 추가 빌드 단계 .h in Link 바이너리 도서관

내가 사용하고 MasterViewController 또는 DetailViewController의 글로벌 상수를 클릭, 오른쪽에있는 도움말 창 그것이 적절한 파일에 선언되어 있음을 보여줍니다 빌드 설정에 새로운 사용자 헤더 검색 경로를 추가합니다.

알려주세요. 미리 감사드립니다.


편집 22/07/2014

내가 & 사용 전역 상수를 정의하는 간단한 응용 프로그램에서 시도합니다. 때 작동 : 헤더에

  • 선언은 블록 @interface의 외부
  • m 개의 파일에 할당 모르겠어요

그러나 외부 블록 @implementation의 얼마나 내가 할 수있는 내 코드를 내 AppDelegate.m 파일의 @implementation 외부에 추가하십시오. 나는이 점을 조사 할 것이다.

+1

'.h' 파일에서 선언 한 모든 변수의 * extern * 정의가없는'.m' 파일이 필요합니다. extern을 사용하면 변수의 정의가 다른 곳에서 발견된다는 것을 알 수 있습니다. 그러나 그 정의가 어디에 있든, 앱에 연결되어 있지 않습니다. – Petesh

+0

Hello @Petesh. 내 상수는 내 AppDelegate.m에 할당되며이 파일은 컴파일 소스에 추가됩니다. 'NSData * const JQUERY_FILE = [NSData dataWithContentsOfURL : url];''JQUERY_FILE = [NSData dataWithContentsOfURL : url];에 의해 .m 파일을 삭제하는 경우 '읽기 전용 변수를 할당 할 수 없습니다. – Karine

답변

0

다른의 UIViewController에서 AppDelegate에 내에서 속성에 액세스하려는 경우이 도움이 될 수

AppDelegate에 있다.시간 당신은

@property (strong, nonatomic) NSData *someData; 

당신의 AppDelagate.m의 데이터를 생성 속성을 선언 할

다음
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

[self generateData]; 
//any other code 
} 

-(void) generateData{ 
//Populate your property 
_someData = [NSData dataWithContentsOfURL:url]; 
} 

이 할 수있는 또 다른 UIView의 컨트롤러에서 데이터에 액세스 할 수 :

을 SomeViewController.m

NSData * localSomeData = [(AppDelegate *)[[UIApplication sharedApplication] delegate] someData]; 
+0

응답 주셔서 감사하지만 전역 상수 대신 메서드를 사용하는 것이 좋습니다. 당신의 해결책은 제 문제를 오도하게 만듭니다. 내 목표는 코드를 줄이기 위해 전역 상수를 사용하는 것이다. 파일이 기기에 다운로드되고 저장되지만 필요할 때마다 검색하고 싶지 않습니다. – Karine

0

다음 코드로 문제를 해결했습니다. 필자는 런타임에 값을 설정하기 때문에 상수를 사용할 수 없습니다. 이 문제를 해결하기위한 해결책을 찾지 못했습니다. 그래서 저는 전역 변수를 선택합니다. AppDelegate.h에서

:

// GLOBAL VARIABLES 
// javascript & css files 
extern NSData *JQUERY_FILE; 
extern NSData *JQUERYUI_FILE; 
extern NSData *JQUERY_MOBILE_FILE; 
extern NSData *JQUERY_MOBILE_CSS_FILE; 
// json files 
extern NSData *APPLICATION_FILE; 
extern NSData *FEED_FILE; 
// END GLOBAL VARIABLES 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@end 

AppDelegate.m에서 : 전역 변수를 사용하려는

#import "AppDelegate.h" 

NSData *JQUERY_FILE; 
NSData *JQUERYUI_FILE; 
NSData *JQUERY_MOBILE_FILE; 
NSData *JQUERY_MOBILE_CSS_FILE; 
NSData *APPLICATION_FILE; 
NSData *FEED_FILE; 

@implementation AppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) { 
    UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 
    UINavigationController *navigationController = [splitViewController.viewControllers lastObject]; 
    splitViewController.delegate = (id)navigationController.topViewController; 
} 

#pragma Download & save javascript & css files 
NSLog(@"%@", NSHomeDirectory()); 

NSError *error = [[NSError alloc] init]; 

// Get the Bundle identifier for creating dynamic path for storing all files 
NSString *bundle = [[NSBundle mainBundle] bundleIdentifier]; 
// NSHomeDirectory returns the application's sandbox directory 
// FileManager is using for creating the Application Support Folder 
NSFileManager *fileManager = [NSFileManager defaultManager]; 
NSURL *appliSupportDir = [fileManager URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&error]; 
[appliSupportDir URLByAppendingPathComponent:bundle isDirectory:YES]; 

// Get jquery files in network 
NSURL *url = [NSURL URLWithString:@"http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"]; 
NSString *path = [NSString stringWithFormat:@"%@/Library/Application Support/jquery.js", NSHomeDirectory()]; 
//JQUERY_FILE = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; 
JQUERY_FILE = [NSData dataWithContentsOfURL:url]; 
[[NSData dataWithContentsOfURL:url] writeToFile:path options:NSDataWritingAtomic error:&error]; 

url = [NSURL URLWithString:@"http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.min.js"]; 
path = [NSString stringWithFormat:@"%@/Library/Application Support/jqueryUI.js", NSHomeDirectory()]; 
//JQUERYUI_FILE = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; 
JQUERYUI_FILE = [NSData dataWithContentsOfURL:url]; 
[[NSData dataWithContentsOfURL:url] writeToFile:path options:NSDataWritingAtomic error:&error]; 

url = [NSURL URLWithString:@"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"]; 
path = [NSString stringWithFormat:@"%@/Library/Application Support/jqueryMobile.js", NSHomeDirectory()]; 
//JQUERY_MOBILE_FILE = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; 
JQUERY_MOBILE_FILE = [NSData dataWithContentsOfURL:url]; 
[[NSData dataWithContentsOfURL:url] writeToFile:path options:NSDataWritingAtomic error:&error]; 

url = [NSURL URLWithString:@"http://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.css"]; 
path = [NSString stringWithFormat:@"%@/Library/Application Support/jqueryMobileCSS.css", NSHomeDirectory()]; 
//JQUERY_MOBILE_CSS_FILE = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&error]; 
JQUERY_MOBILE_CSS_FILE = [NSData dataWithContentsOfURL:url]; 
[[NSData dataWithContentsOfURL:url] writeToFile:path options:NSDataWritingAtomic error:&error]; 


#pragma Download & save Json Files 
// Read Json file in network. WARNING : ID EN DUR !! 
// Get Application File 
url = [NSURL URLWithString:@"http://testapp.visionit.lan:8087/api/application/79e45c6e-9e87-4576-b028-609ae2902f00"]; 
path = [NSString stringWithFormat:@"%@/Library/Application Support/myApplication.json", NSHomeDirectory()]; 
APPLICATION_FILE = [NSData dataWithContentsOfURL:url]; 
[APPLICATION_FILE writeToFile:path options:NSDataWritingAtomic error:&error]; 
// Get Feed File 
url = [NSURL URLWithString:@"http://testapp.visionit.lan:8087/api/feed/79e45c6e-9e87-4576-b028-609ae2902f00"]; 
path = [NSString stringWithFormat:@"%@/Library/Application Support/myFeed.json", NSHomeDirectory()]; 
FEED_FILE = [NSData dataWithContentsOfURL:url]; 
[FEED_FILE writeToFile:path options:NSDataWritingAtomic error:&error]; 


return YES; 
} 

다음으로, AppDelegate.h를 가져옵니다.

나를 위해 작동합니다. 희망 하시겠습니까?

관련 문제