在 Ubuntu 10.10 環境下交叉編譯 ARM 版 Qt 時,編譯過程中止並報錯:
thread/qthread_unix.cpp:117: error: thread-local storage not supported for this target
make[1]: *** [.obj/release-shared-emb-arm/qthread_unix.o] Error 1
檢查 src/corelib/thread/qthread_unix.cpp 發現,程式碼透過 HAVE_TLS 巨集控制執行緒區域儲存 (Thread-Local Storage, TLS) 功能。ARM 交叉編譯工具鏈預設不支援 TLS,導致編譯失敗。
vi src/corelib/thread/qthread_unix.cpp#define HAVE_TLS
#endif
#if defined(Q_CC_XLC) || defined(Q_CC_SUN)
#define HAVE_TLS
#endif
#ifdef HAVE_TLS
static __thread QThreadData *currentThreadData = 0;
#endif
#define HAVE_TLS 註解或移除,使 TLS 相關程式碼不被編譯:// #define HAVE_TLS
#endif
#if defined(Q_CC_XLC) || defined(Q_CC_SUN)
// #define HAVE_TLS
#endif
#ifdef HAVE_TLS
static __thread QThreadData *currentThreadData = 0;
#endif
make,編譯即可通過。此修改會停用 TLS 快取機制,可能略微影響執行緒切換效能,但在不支援 TLS 的 ARM 平台上是必要的妥協。若工具鏈升級支援 TLS,可考慮恢復該巨集。