如果我尝试在这个文件上实现我的类,我会收到一个错误UnsatisfiedLinkError,但是如果我删除了Broker.h类的实现,它就可以了。为什么呢?

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
有帮助吗?

解决方案

您的图书馆可能会错过对某些符号或其他图书馆的引用。尝试使用空的main()函数创建一些main.cpp,并将其链接到您的库 - g ++ main.cpp -o main -lInterAppCC 。如果您遗漏了某些内容,链接器将为您提供详细的错误消息。

PS。由于您的头文件已经使用 extern&quot; C&quot; 包装了函数原型,因此在编写实现时不需要执行相同的操作。

其他提示

您需要使用extern“C”围绕JNIEXPORT的东西,避免c ++名称重写JNI函数。

C ++名称修改更改函数名称(在obj文件中)以包括参数类型,虚拟等,以便能够使用相同名称链接不同的重载函数。

所以,用extern“C”包装你的JNIEXPORT。 {...}(查看JNI标题)并确保您的c ++代码不包含在内。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top