Question

J'utilise C ++ pour développer la partie algorithmique d'une application iPhone, et je suis confronté à un bug étrange. Le code que j'ai, compile très bien avec gcc-4.2 aussi bien sur Linux, le Mac, et sur l'appareil iPhone, mais pas sur le simulateur, ce qui rend le débogage et le test très difficile.

Les messages d'erreur, les tentatives de compilation pour le simulateur ressemble à un bug connu dans 4.0.x, bien que ce n'est pas très clair pourquoi depuis que je l'ai mis explicitement gcc-4.2 pour être le compilateur par défaut.

Pour démontrer le bug, je l'ai préparé le petit extrait de code suivant:

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); 
} 

et puis essayé de le compiler comme suit:

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 

Eventhough J'utilise pour compiler gcc-4.2 pour le simulateur, je reçois le même message d'erreur comme si je compilaient sous-gcc 4.0, à savoir:

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>&)

Toutes les idées pour lesquelles ce bug gcc-4.0.x se glisse dans le simulateur, alors que le simulateur est censé être en utilisant gcc-4.2.x où ce bug a été corrigé?

Était-ce utile?

La solution

Je ne sais pas si cela est exactement la bonne réponse, mais ce serait sans doute expliquer pourquoi vous voyez le comportement 4.0 en utilisant 4.2:

> 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

On dirait qu'ils essaient d'utiliser au moins sur Snow Leopard set 4.0 en-tête pour les deux versions, avec Xcode 3.2.

Autres conseils

Je vérifierai soigneusement les en-têtes de bibliothèque (STL) que le simulateur fait référence.

Parfois, il y a des questions de compilateur dans Xcode, peut-être vous avez un problème analogue à celui décrit ici.

UIKit Erreur SDK

Dans ce cas, vous devez spécifier le compilateur spécifiquement pour l'appareil et simulateur. Je sais que cela ne fait pas de sens, mais il fixe mon problème.

Il y a un problème avec les itérateurs de ne pas avoir unordered_map des constructeurs par défaut dans gcc-4.0.x

http://bytes.com/topic/c/ réponses / 607427-error-TR1-unordered_map-iterator

Initialisation sur déclaration devrait fixer:

for(dict::const_iterator it = c1.begin(); it != c1.end(); it++)
    std::cout << it->first << std::endl;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top