2014-07-19 79 views
0

目前我正在使用Android NDK。我有點困惑,因爲它應該在VisualStudio中工作,在Andorid NDK中無法編譯。 我有"Accessories.h"Android NDK中的未知類型名稱錯誤

Accessories.h 
#ifndef _ACCESSORIES_H_ 
#define _ACCESSORIES_H_ 

#ifdef __cplusplus 
extern "C" { 
#endif 
struct container{ 

    int numofppl; 
    int camera_idx; 
    unsigned char *frame;//image buffer 
    container(); 
}; 

#ifdef __cplusplus 
} 
#endif 
#endif 

我已經jniexport.c作爲

jniexport.c 
#include "jniexport.h" 
#include "Accessories.h" 
void *pthread_func(void *proc_ctrl); 
JNIEXPORT jint Java_com_countPeople 
    (JNIEnv *env, jclass obj, jint do_processing) 
{ 
    int ret; 
    int rc; 
    void *status; 
    pthread_t proc_thread; 
    pthread_attr_t attr; 
    /* Initialize and set thread detached attribute */ 
    pthread_attr_init(&attr); 
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); 

    rc = pthread_create(&proc_thread, NULL, pthread_func, (void *)do_processing); 

    pthread_attr_destroy(&attr); 
    pthread_join(proc_thread, &status); 
    if (!(int)status){//normal exit 
     //pass info to Android UI 

     ret = 0; 
    }else{//problem 
     //pass info to Android UI 

    } 
    pthread_exit(NULL); 
    return ret; 
} 

void *pthread_func(void *proc_ctrl) 
{ 
    int ctrl = (int)proc_ctrl; 
    container *ct; 

    while(ctrl){ 
     ct = calloc(1,sizeof (container)); 
     if(ct == NULL){ 
      pthread_exit((void*) 1);//Memory allocation error 
     } 
     ct.numofppl = 0; 
     ct.camera_idx = 0; 
     ct.frame = camera_get_snapshot(); 
     //Do face detection 
     facedetection(ct); 

     free(ct.frame); 
     free(ct); 
    } 

    pthread_exit((void*) 0); 
} 

當我ndk-build,錯誤如下

In function 'pthread_func': 
error: unknown type name 'container' 
error: 'container' undeclared (first use in this function) 
note: each undeclared identifier is reported only once for each function it appear 
s in 
error: request for member 'numofppl' in something not a structure or union 
error: request for member 'camera_idx' in something not a structure or union 
error: request for member 'frame' in something not a structure or union 

回答

2

你沒有typedef容器,所以您在創建時需要始終使用struct container NAME如果你在C,你的struct的變量。

所以它需要是struct container ct*(同樣你需要修復你的malloc調用)。或者你可以簡單包裝結構定義在typedef

typedef struct{ 
... 
} container; 

然後你可以只使用container NAME

其餘的錯誤來自它不知道什麼container ct*是一種類型。