【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】
또한 수수께끼의 오류 ...
Xcode로 빌드했을 때 수수께끼의 오류가 나오는 경우가 있습니다.
「에, 체크아웃한 것만으로, 특히 아무것도 코드 바꾸지 않았는데 무엇으로 에러!?」
이런 일도 있습니다.
물론 오류는 상황에 따라 다양하지만 그 중에서도 cocos2d-x를 사용한다면
만날 수 있는 에러와 그 해결 방법을 소개합니다.
샘플 만들기
전체 코드는 github에 UP했습니다. → 이쪽
이번에는 에러를 발생시킬 가능성이 있는, iOS , aOS에서 처리를 분리할 필요가 있는 프로그램을 cocos2d-x로 준비했습니다.
또한 사용한 cocos2d-x의 Version은 3.3rc0입니다.
NativeUtil.h// NativeUtil.h
#ifndef __Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__
#define __Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__
#include <stdio.h>
class NativeUtil
{
public:
static void showWebBrowser(std::string url);
};
#endif /* defined(__Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__) */
NativeUtil.cpp// NativeUtil.cpp
#include "NativeUtil.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
/**
* URLを指定して端末ブラウザと連携する
*/
void NativeUtil::showWebBrowser(std::string url)
{
NSString *urlString = [NSString stringWithFormat:@"%s" , url.c_str()];
NSURL *nsUrl = [NSURL URLWithString:urlString];
// ブラウザを起動する
[[UIApplication sharedApplication] openURL:nsUrl];
}
동작 확인
이런 느낌입니다.
어디까지나 샘플이므로, 살짝 읽어 날려 주세요.
가운데 버튼을 누르면 단말기 브라우저와 연동합니다.

이 예에서는 cocos2d-x의 웹 사이트로 전환했습니다.

그래? NSObjCRuntime 오류! ?
오류가 발생했습니다. 이런 오류입니다.

이런 에러는 특별히 보고 싶지 않네요.
원인
이것이 원인입니다.

이
Type : Default - C++ Source
때문에이 오류가 발생합니다.
오류 내용을 읽으면
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:397:1: error: expected unqualified-id
@class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:399:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
이런 느낌이지만,
씹어서 설명하면,
・C++의 코드 내에 Objective-C의 코드가 섞여 있는데, 그 Objective-C의 코드를 인식할 수 없다
이런 오류 내용이 됩니다.
또한 아마도 파일 확장자가 cpp 일 때만 발생하는 오류가 아닐까 생각됩니다.
해결책
두 가지가 있습니다.
1. 파일 확장자를 .mm로 변경
이것은 그대로입니다.
아시다시피, .mm로 설정하면 자동으로 Obj-C++ 파일이되므로,
혼합 코드에서도 Xcode가 자동으로 인식합니다.
2. Type을 Objective-C++ Source로 변경
지정된 cpp 파일을 선택하면 해당 파일의 Type을 볼 수 있습니다.
그것을 아래와 같이, Objective-C++ Source 로 바꾸어 주면 OK입니다.

이제 빌드가 통과하게 됩니다.
마지막으로
가능하면 이런 에러에는 만나고 싶지 않다…
드물게 만나는 일은 없다고 생각하지만,
만일 만나버린 분의 도움이 되면 다행입니다.
Reference
이 문제에 관하여(【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kuuki_yomenaio/items/6edc7cb16a81d2bc9ef5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
전체 코드는 github에 UP했습니다. → 이쪽
이번에는 에러를 발생시킬 가능성이 있는, iOS , aOS에서 처리를 분리할 필요가 있는 프로그램을 cocos2d-x로 준비했습니다.
또한 사용한 cocos2d-x의 Version은 3.3rc0입니다.
NativeUtil.h
// NativeUtil.h
#ifndef __Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__
#define __Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__
#include <stdio.h>
class NativeUtil
{
public:
static void showWebBrowser(std::string url);
};
#endif /* defined(__Cocos2dxNSObjCRuntimeErrorTest__NativeUtil__) */
NativeUtil.cpp
// NativeUtil.cpp
#include "NativeUtil.h"
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
/**
* URLを指定して端末ブラウザと連携する
*/
void NativeUtil::showWebBrowser(std::string url)
{
NSString *urlString = [NSString stringWithFormat:@"%s" , url.c_str()];
NSURL *nsUrl = [NSURL URLWithString:urlString];
// ブラウザを起動する
[[UIApplication sharedApplication] openURL:nsUrl];
}
동작 확인
이런 느낌입니다.
어디까지나 샘플이므로, 살짝 읽어 날려 주세요.
가운데 버튼을 누르면 단말기 브라우저와 연동합니다.

이 예에서는 cocos2d-x의 웹 사이트로 전환했습니다.

그래? NSObjCRuntime 오류! ?
오류가 발생했습니다. 이런 오류입니다.

이런 에러는 특별히 보고 싶지 않네요.
원인
이것이 원인입니다.

이
Type : Default - C++ Source
때문에이 오류가 발생합니다.
오류 내용을 읽으면
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:397:1: error: expected unqualified-id
@class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:399:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
이런 느낌이지만,
씹어서 설명하면,
・C++의 코드 내에 Objective-C의 코드가 섞여 있는데, 그 Objective-C의 코드를 인식할 수 없다
이런 오류 내용이 됩니다.
또한 아마도 파일 확장자가 cpp 일 때만 발생하는 오류가 아닐까 생각됩니다.
해결책
두 가지가 있습니다.
1. 파일 확장자를 .mm로 변경
이것은 그대로입니다.
아시다시피, .mm로 설정하면 자동으로 Obj-C++ 파일이되므로,
혼합 코드에서도 Xcode가 자동으로 인식합니다.
2. Type을 Objective-C++ Source로 변경
지정된 cpp 파일을 선택하면 해당 파일의 Type을 볼 수 있습니다.
그것을 아래와 같이, Objective-C++ Source 로 바꾸어 주면 OK입니다.

이제 빌드가 통과하게 됩니다.
마지막으로
가능하면 이런 에러에는 만나고 싶지 않다…
드물게 만나는 일은 없다고 생각하지만,
만일 만나버린 분의 도움이 되면 다행입니다.
Reference
이 문제에 관하여(【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kuuki_yomenaio/items/6edc7cb16a81d2bc9ef5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
오류가 발생했습니다. 이런 오류입니다.

이런 에러는 특별히 보고 싶지 않네요.
원인
이것이 원인입니다.

이
Type : Default - C++ Source
때문에이 오류가 발생합니다.
오류 내용을 읽으면
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:397:1: error: expected unqualified-id
@class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:399:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
이런 느낌이지만,
씹어서 설명하면,
・C++의 코드 내에 Objective-C의 코드가 섞여 있는데, 그 Objective-C의 코드를 인식할 수 없다
이런 오류 내용이 됩니다.
또한 아마도 파일 확장자가 cpp 일 때만 발생하는 오류가 아닐까 생각됩니다.
해결책
두 가지가 있습니다.
1. 파일 확장자를 .mm로 변경
이것은 그대로입니다.
아시다시피, .mm로 설정하면 자동으로 Obj-C++ 파일이되므로,
혼합 코드에서도 Xcode가 자동으로 인식합니다.
2. Type을 Objective-C++ Source로 변경
지정된 cpp 파일을 선택하면 해당 파일의 Type을 볼 수 있습니다.
그것을 아래와 같이, Objective-C++ Source 로 바꾸어 주면 OK입니다.

이제 빌드가 통과하게 됩니다.
마지막으로
가능하면 이런 에러에는 만나고 싶지 않다…
드물게 만나는 일은 없다고 생각하지만,
만일 만나버린 분의 도움이 되면 다행입니다.
Reference
이 문제에 관하여(【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kuuki_yomenaio/items/6edc7cb16a81d2bc9ef5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:397:1: error: expected unqualified-id
@class NSString, Protocol;
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.0.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:399:19: error: unknown type name 'NSString'
FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL aSelector);
두 가지가 있습니다.
1. 파일 확장자를 .mm로 변경
이것은 그대로입니다.
아시다시피, .mm로 설정하면 자동으로 Obj-C++ 파일이되므로,
혼합 코드에서도 Xcode가 자동으로 인식합니다.
2. Type을 Objective-C++ Source로 변경
지정된 cpp 파일을 선택하면 해당 파일의 Type을 볼 수 있습니다.
그것을 아래와 같이, Objective-C++ Source 로 바꾸어 주면 OK입니다.

이제 빌드가 통과하게 됩니다.
마지막으로
가능하면 이런 에러에는 만나고 싶지 않다…
드물게 만나는 일은 없다고 생각하지만,
만일 만나버린 분의 도움이 되면 다행입니다.
Reference
이 문제에 관하여(【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kuuki_yomenaio/items/6edc7cb16a81d2bc9ef5
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(【iOS】Xcode로 빌드했을 때 NSObjCRuntime에서 에러? 【cocos2d-x】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kuuki_yomenaio/items/6edc7cb16a81d2bc9ef5텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)