我正在使用C++開發iPhone應用程序的算法部分,並遇到一個奇怪的錯誤。我擁有的代碼,在Linux,Mac和iPhone設備上均可使用gcc-4.2進行編譯,而不是在Simulator上,這使得調試和測試變得非常困難。爲iPhone設備編譯但不是用於模擬器的代碼
來自嘗試編譯模擬器的錯誤消息類似於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);
}
,然後試圖進行如下編譯:
編譯。 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我使用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,這個錯誤已經修復了。
+1最小的和簡單的清樣代碼 - 應該詢問代碼相關的問題 – sbk 2009-09-20 05:35:04
xcode 3.1或3.2?雪豹或豹子? gcc/g ++附帶xcode或其他? – slf 2009-09-21 21:52:42