Android NDK中的未知类型名称错误

时间:2014-07-19 16:40:30

标签: c++ c android-ndk

目前我在Android NDK工作。我有点困惑,因为它应该在VisualStudio中工作,在Andorid NDK中无法编译。 我有"Accessories.h"

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

1 个答案:

答案 0 :(得分:2)

您没有typedef容器,因此如果您在C中,则需要在创建struct container NAME变量时始终使用struct

因此需要struct container ct*(同样需要修复malloc次来电)。或者您可以简单地将结构定义包装在typedef

typedef struct{
...
} container;

然后你可以使用container NAME

其余的错误来自于它不知道container ct*是什么类型。