Reputation: 7314
Currently I am working in Android NDK. I am a little bit confused as the thing it should work in VisualStudio, doesn't work compiling in Andorid NDK.
I have "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
I have jniexport.c
as
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);
}
When I ndk-build
, the error is as follows
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
Upvotes: 0
Views: 1083
Reputation: 9115
You didn't typedef
container, so you need to always use struct container NAME
when creating variables of your struct
if you're in C.
So it needs to be struct container ct*
(and similarly you need to fix your malloc
calls). Or you can simply wrap the struct definition in a typedef
:
typedef struct{
...
} container;
And then you can just use container NAME
.
The rest of the errors come from it not knowing what container ct*
is as a type.
Upvotes: 2