Я использую C ++ для разработки алгоритмической части приложения для iPhone, и я столкнулся со странной ошибкой. Код, который у меня есть, прекрасно компилируется с gcc-4.2 как на Linux, на Mac, так и на устройстве iPhone, но не на Simulator, что делает отладку и тестирование очень трудными.
Сообщения об ошибках при попытках компиляции для симулятора напоминают известную ошибку в 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.0.x проникает в симулятор, когда на самом деле симулятор должен использовать gcc-4.2.x, где эта ошибка была исправлена?