tags:

views:

266

answers:

2

If I try to implement my class on this file I get an error UnsatisfiedLinkError, however if I remove the implementation of the Broker.h Class it goes ok. Why?

Broker.h

#include "XletTable.h"

#ifndef BROKER_H_
#define BROKER_H_

class Broker {
private:
    static Broker* brokerSingleton;
    static XletTable *table;

    // Private constructor for singleton
    Broker(JNIEnv *, XletTable *);

    // Get XletTable (Hash Table) that contains the...
    static XletTable* getTable();

public:
    virtual ~Broker();
    static Broker* getInstance(JNIEnv *);
    jobject callMethod(JNIEnv *, jclass, jstring, jobject, jbyteArray);
};

#endif /* BROKER_H_ */

BrokerJNI.h

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class Broker */

#ifndef _Included_Broker
#define _Included_Broker
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     Broker
 * Method:    callMethod
 * Signature: (Ljava/lang/String;Ljava/lang/reflect/Method;[B)Ljava/lang/Object;
 */
JNIEXPORT jobject JNICALL Java_Broker_callMethod
  (JNIEnv *, jclass, jstring, jobject, jbyteArray);

#ifdef __cplusplus
}
#endif
#endif
+2  A: 

You need to use extern "C" around the JNIEXPORT stuff, to avoid c++ name mangling of the JNI functions.

C++ name mangling changes function names (in the obj-files) to include the types of parameters, virtual-ness, etc, to be able to link different overloaded functions with the same name.

So, wrap your JNIEXPORT with extern "C" { ... } (look at the JNI header) and make sure your c++-code isn't wrapped in the same.

Marcus Lindblom
I did what you say, wrapped the entire JNIEXPORT with "external "C" { } still no luck...
Marcos Roriz
Could you edit your question and add the new code in it's entirety?
Marcus Lindblom
done editing the question
Marcos Roriz
+1  A: 

Probably your library miss reference to some symbol, or another library. Try make some main.cpp with empty main() function, and link it with your library - g++ main.cpp -o main -lInterAppCC. If you miss something, the linker will give you a detailed error message.

PS. Since your header file already wraps function prototype with extern "C", you don't required to do the same when writing implementation.

Xeor
Got an strange error:ld libInterAppCC.sold: warning: cannot find entry symbol _start; not setting start addresslibInterAppCC.so: undefined reference to `Broker::brokerSingleton'libInterAppCC.so: undefined reference to `vtable for IxcRegistry'libInterAppCC.so: undefined reference to `Broker::table'libInterAppCC.so: undefined reference to `IxcRegistry::table'libInterAppCC.so: undefined reference to `IxcRegistry::cppRegistrySingleton'libInterAppCC.so: undefined reference to `IxcRegistry::getXletTable()'
Marcos Roriz
Now you know exactly what symbols are missing. First, you need to add declarations of static variables in C++ file: `Broker* Broker::brokerSingleton; XletTable* Broker::table;`. Then you need to understand what's going on with other missing symbol: did you miss to add link to library that contains IxcRegistry when linking your JNI library?
Xeor
Thanks, now I put those stuff there,now I'm getting only this errors:ld: warning: cannot find entry symbol _start; not setting start addresslibInterAppCC.so: undefined reference to `vtable for IxcRegistry'libInterAppCC.so: undefined reference to `IxcRegistry::getXletTable()'I'll post my IxcRegistry in the question
Marcos Roriz