8

私はC++を使用してiPhoneアプリケーションのアルゴリズム部分を開発していますが、奇妙なバグが発生しています。私が持っているコードは、Linux、Mac、iPhoneデバイスの両方でgcc-4.2で正常にコンパイルされますが、シミュレーターではコンパイルされないため、デバッグとテストが非常に困難になります。

シミュレーター用にコンパイルしようとしたときのエラーメッセージは、4.0.xの既知のバグに似ていますが、gcc-4.2をデフォルトのコンパイラーとして明示的に設定しているため、理由はあまり明確ではありません。

バグを示すために、次の小さなコードスニペットを用意しました。

bug.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.2.xを使用しているはずなのに、なぜこのgcc-4.0.xバグがシミュレーターに忍び寄るのかについてのアイデアはありますか?

4

3 に答える 3

4

これが正確に正しい答えであるかどうかはわかりませんが、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

少なくともXcode3.2を搭載したSnowLeopardでは、両方のバージョンに4.0ヘッダーセットを使用しようとしているようです。

于 2009-09-22T01:06:18.897 に答える
0

Xcodeにコンパイラの問題がある場合もありますが、ここで説明する問題に類似した問題がある場合もあります。

UIKitSDKエラー

この場合、デバイスとシミュレーター専用のコンパイラーを指定する必要があります。これは意味がないことは知っていますが、問題は解決しました。

于 2009-09-21T07:46:39.733 に答える
0

シミュレーターが参照しているライブラリー(STL)ヘッダーを注意深くチェックします。

于 2009-09-20T04:16:32.477 に答える