iPhone 기기에 대해 컴파일하지만 시뮬레이터에 대해서는 컴파일하는 코드

StackOverflow https://stackoverflow.com/questions/1450133

  •  11-09-2019
  •  | 
  •  

문제

나는 iPhone 응용 프로그램의 알고리즘 부분을 개발하기 위해 C ++를 사용하고 있으며 이상한 버그가 발생하고 있습니다. 내가 가진 코드는 Linux, Mac 및 iPhone 장치에서 GCC-4.2에서 잘 컴파일하여 시뮬레이터가 아닌 iPhone 장치에서 디버깅 및 테스트가 매우 어려워집니다.

시뮬레이터를 컴파일하려는 시도의 오류 메시지는 4.0.x에서 알려진 버그와 유사하지만 GCC-4.2를 기본 컴파일러로 명시 적으로 설정했기 때문에 왜 명확하지 않습니다.

버그를 보여주기 위해 다음과 같은 작은 코드 스 니펫을 준비했습니다.

ug.cpp

#include <tr1/unordered_map>
#include <iostream>

/* a hash key for the visitedTrip table */
struct X {
    int x;

    X() : x(0){};
    X(int x) : x(x){};
};


typedef std::tr1::unordered_map<int,X> dict;

int main() 
{ 
    dict c1; 

    X a(0);
    X b(1);
    X c(2);

    c1[0] = a;
    c1[1] = b;
    c1[2] = c;

    dict::const_iterator it;

    for(it = c1.begin(); it != c1.end(); it++)
        std::cout << it->first << std::endl;

    return (0); 
} 

그런 다음 다음과 같이 컴파일하려고했습니다.

compile.sh

#!/bin/bash

#
# Compiling for the simulator and compiling under gcc-4.0 return the same error message
#

#SUCCESS
c++-4.2 -arch i386 bug.cpp

#FAIL 
c++-4.0 -arch i386 bug.cpp

#SUCCESS
gcc-4.2 -arch i386 -c bug.cpp

#FAIL
gcc-4.0 -arch i386 -c bug.cpp

#FAIL
gcc-4.2 -arch i386 -c bug.cpp -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk 

GCC-4.2를 사용하여 시뮬레이터를 위해 컴파일하는 경우 GCC-4.0에서 컴파일하는 것처럼 동일한 오류 메시지가 나타납니다.

bug.cpp:27: error: no matching function for call to ‘Internal::hashtable_iterator<std::pair<const int, X>, false, false>::hashtable_iterator()’
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/c++/4.2.1/tr1/hashtable:236: note: candidates are: Internal::hashtable_iterator<Value, is_const, cache>::hashtable_iterator(const Internal::hashtable_iterator<Value, true, cache>&) [with Value = std::pair<const int, X>, bool is_const = false, bool cache = false]
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/c++/4.2.1/tr1/hashtable:234: note:                 Internal::hashtable_iterator<Value, is_const, cache>::hashtable_iterator(Internal::hash_node<Value, cache>**) [with Value = std::pair<const int, X>, bool is_const = false, bool cache = false]
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/c++/4.2.1/tr1/hashtable:232: note:                 Internal::hashtable_iterator<Value, is_const, cache>::hashtable_iterator(Internal::hash_node<Value, cache>*, Internal::hash_node<Value, cache>**) [with Value = std::pair<const int, X>, bool is_const = false, bool cache = false]
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/c++/4.2.1/tr1/hashtable:225: note:                 Internal::hashtable_iterator<std::pair<const int, X>, false, false>::hashtable_iterator(const Internal::hashtable_iterator<std::pair<const int, X>, false, false>&)

이 GCC-4.0.x 버그가 왜 시뮬레이터가 시뮬레이터로 들어 오는지에 대한 아이디어는 실제로 시뮬레이터 가이 버그가 고정 된 곳에서 GCC-4.2.x를 사용해야 할 때?

도움이 되었습니까?

해결책

이것이 정확히 정답인지 확실하지 않지만 아마도 4.2를 사용하는 동안 4.0 동작을 보는 이유를 설명 할 것입니다.

> pwd
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/include/c++
> ls -l
total 4
drwxr-xr-x  10 root  wheel  2278 10 Sep 09:32 4.0.0/
lrwxr-xr-x   1 root  wheel     5 10 Sep 09:30 4.2.1@ -> 4.0.0

Xcode 3.2가있는 스노우 레오파드에서는 두 버전 모두 4.0 헤더 세트를 사용하려고하는 것 같습니다.

다른 팁

시뮬레이터가 참조하는 라이브러리 (STL) 헤더를주의 깊게 확인할 것입니다.

때로는 Xcode에 컴파일러 문제가 있는데, 아마도 여기에 설명 된 것과 유사한 문제가있을 수 있습니다.

Uikit SDK 오류

이 경우 장치 및 시뮬레이터 용 컴파일러를 구체적으로 지정해야합니다. 나는 이것이 의미가 없다는 것을 알고 있지만 그것은 내 문제를 해결했습니다.

gcc-4.0.x에 기본 생성자가없는 unordered_map의 반복자에 문제가 있습니다.

http://bytes.com/topic/c/answers/607427-error-tr1-unordered_map-eritorator

선언시 초기화를 수정해야합니다.

for(dict::const_iterator it = c1.begin(); it != c1.end(); it++)
    std::cout << it->first << std::endl;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top