2017-02-10 208 views
0

嘗試編譯項目,並在thread.h中收到此錯誤。錯誤:未知類型名稱'pthread_mutex_t'

inc/thread.h:38:15: error: unknown type name 'pthread_mutex_t' 

當我看着thread.h,我看到以下內容:

#include <pthread.h> 
#include "rel_assert.h" 
#define MUTEX pthread_mutex_t 

這是導致該錯誤的最後一行。 搜索後,我在pthreadtypes.h中找到了pthread_mutex_t結構體定義,所以我試圖包含它。然後我以下錯誤:

inc/pthreadtypes.h:16:3: error: #error "Never include <bits/pthreadtypes.h> directly; use <sys/types.h> instead." inc/pthreadtypes.h:23:24: fatal error: bits/sched.h: No such file or directory compilation terminated.

如果我有<sys/types.h>相反,我回到我原來的錯誤。 任何想法如何解決這個問題。

UPDATE1 儘量把主要的是這樣開始時來定義它:

#include <pthread.h> 
//#include <libbladeRF.h> 
#include <sys/types.h> 

int main() 
{ 

pthread_mutex_t m; 
return 0; 
} 

當我做一個獨立的C文件,並在命令行編譯GCC這個實際工作。但在該項目中,我收到錯誤。當我創建項目時,我一定做錯了什麼。將再試一次。

+1

由於錯誤提示你:還包括''(而不是'') –

+0

那麼你包含哪些文件? –

+1

試着把'pthread_mutex_t MUTEX'沒有'#define' –

回答

0

包括「pthread.h」和「SYS/types.h中後,」頭文件,應該不會有什麼問題。可能是你可以交叉驗證你正在構建這段代碼的環境。

我希望你在編譯你的代碼時使用了'pthread'庫(使用「-lpthread」選項)

+0

我在哪裏添加? 我試過像這樣: 'nios2-elf-gcc -xc -lpthread -MP -MMD -c' –

+0

我的意思是在代碼中它需要包含這些頭文件,但我發現你已經在做這件事了。請讓我知道,你正在試圖編譯的環境。可能是你必須交叉檢查你的環境一次。 –