Pregunta

Estoy usando C ++ para desarrollar la parte algorítmica de una aplicación de iPhone, y me encuentro con un extraño insecto. El código que tengo, compila bien con gcc-4.2 tanto en Linux, en el Mac, y en el dispositivo iPhone, pero no en el simulador, lo que hace que la depuración y prueba muy difícil.

El error de los mensajes de los intentos para compilar para el simulador se asemejan a un error conocido en 4.0.x, aunque eso no es muy claro por qué ya que he establecido explícitamente gcc-4.2 que es el compilador por defecto.

Para demostrar el error, he preparado el siguiente pequeño fragmento de código:

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

y luego trataron de recopilar de la siguiente manera:

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 estoy usando gcc-4.2 para compilar para el simulador, yo estoy recibiendo el mismo mensaje de error como si estuviera compilando bajo gcc-4.0, a saber:

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

¿Alguna idea de por qué este error gcc-4.0.x se arrastra en el simulador, cuando en realidad el simulador se supone que se utiliza gcc-4.2.x, donde este error se ha corregido?

¿Fue útil?

Solución

No estoy seguro si esto es exactamente la respuesta correcta, pero esto probablemente explica por qué se está viendo el comportamiento durante el uso de 4.0 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

Parece que están tratando de utilizar el conjunto de cabecera 4.0 para ambas versiones, al menos en Snow Leopard con Xcode 3.2.

Otros consejos

Yo estaría comprobando cuidadosamente las cabeceras de la biblioteca (STL) que el simulador se hace referencia.

A veces hay problemas de compilación en Xcode, tal vez usted tiene un problema análogo al que se describe aquí.

UIKit error SDK

En este caso se tiene que especificar el compilador específicamente para el dispositivo y el simulador. Sé que esto no tiene ningún sentido, pero fijo mi problema.

Hay un problema con los iteradores de unordered_map no tener constructores por defecto en gcc-4.0.x

http://bytes.com/topic/c/ respuestas / 607427-error-TR1-unordered_map-iterador

La inicialización por declaratoria debe solucionarlo:

for(dict::const_iterator it = c1.begin(); it != c1.end(); it++)
    std::cout << it->first << std::endl;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top