Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Ubuntu 10.10 交叉編譯 ARM 版 Qt 遇到 thread-local storage 錯誤解決方案

編輯:Linux 系統常見問題解答

問題背景

在 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,導致編譯失敗。

解決方法:關閉 HAVE_TLS 巨集

  1. 開啟檔案:vi src/corelib/thread/qthread_unix.cpp
  2. 找到約第 110-118 行的巨集定義區塊:
#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
  1. 將 #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
  1. 重新執行 make,編譯即可通過。

補充說明

此修改會停用 TLS 快取機制,可能略微影響執行緒切換效能,但在不支援 TLS 的 ARM 平台上是必要的妥協。若工具鏈升級支援 TLS,可考慮恢復該巨集。

Copyright © Windows教程網 All Rights Reserved