В настоящее время я работаю в 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
Вы не использовали контейнер typedef
, поэтому вам нужно всегда использовать struct container NAME
при создании переменных вашей struct
если вы находитесь на C.
Поэтому он должен быть struct container ct*
(и аналогичным образом вам нужно исправить ваши вызовы malloc
). Или вы можете просто обернуть определение структуры в typedef
:
typedef struct{
...
} container;
И тогда вы можете просто использовать container NAME
.
Остальные ошибки исходят от него, не зная, какой container ct*
является типом.