fge
fge

Reputation: 121780

"error: 'xxx' undeclared" _and_ "error: unused variable 'xxx'" at the same time, in the same file

I have a really weird compilation problem with JNI and don't know how to solve it at all...

This is a function which is called from static context in my Java code:

private static final Logger logger
    = LoggerFactory.getLogger(PamHandle.class);

private static native void initLog(final Logger logger);

static {
    System.loadLibrary("pam4j");
    initLog(logger);
}

The header declaring this function is as follows:

#ifndef __LOG__H__
#define __LOG__H__

#include <jni.h>

JNIEXPORT void JNICALL Java_org_eel_kitchen_pam_PamHandle_initLog(JNIEnv *env,
    jclass cls, jobject jlogger);

struct javaLogger {
    jobject logger;
    jmethodID debugID;
    void (*debug)(JNIEnv *env, struct javaLogger *logger, char *msg);
};

extern struct javaLogger logger;

void debug(JNIEnv *env, struct javaLogger *logger, char *msg);

#endif /* __LOG_H__ */

and this is the C file:

#include "log.h"

struct javaLogger logger;

JNIEXPORT void JNICALL Java_org_eel_kitchen_pam_PamHandle_initLog(JNIEnv *env,
    jclass cls, jobject jlogger)
{
    jclass class = (*env)->GetObjectClass(env, jlogger);

    logger.logger = jlogger;
    logger.debugID = (*env)->GetMethodID(env, class, "debug",
        "(Ljava/lang/String;)V");
    logger.debug = debug;
}

void debug(JNIEnv *env, struct javaLogger *logger, char *msg)
{
    jstring jsmg = (*env)->NewStringUTF(env, (const char *)msg);

    if (jmsg)
        (*env)->CallVoidMethod(env, logger->logger, logger->debugID, jmsg);
}

But when I try to compile it (with gcc -c -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -fPIC -g -c -I$JAVA_HOME/include -I$JAVA_HOME/include/linux log.c), this is the output I get:

log.c: In function ‘debug’:
log.c:20:9: error: ‘jmsg’ undeclared (first use in this function)
log.c:20:9: note: each undeclared identifier is reported only once for each function it appears in
cc1: warnings being treated as errors
log.c:18:13: error: unused variable ‘jsmg’

Uh... I am completely flabbergasted. What is going on here? :/ I must be missing something very obvious, I just cannot figure what...

Upvotes: 0

Views: 600

Answers (1)

Mat
Mat

Reputation: 206831

jmsg and jsmg are two different things.

Upvotes: 4

Related Questions