我有:
class XCClass
{
@native protected def createWin(displayPtr: Long, width: Int, height: Int, backGroundColour: Int = white.value,
borderColour: Int = darkblue.value, borderWidth: Int = 0, xPosn: Int = 0, yPosn: Int = 0): Long
@native protected def xOpen(): Long
System.load("/sdat/projects/prXCpp/Release/libprXCpp.so")
//Code edited out
class Window(width: Int, height: Int, backGroundColour: ColourInt = white, borderColour: ColourInt = darkblue,
borderWidth: Int = 0, xPosn: Int = 0, yPosn: Int = 0)
{
val xWinPtr = createWin(xServPtr, width, height, backGroundColour.value, borderColour.value, borderWidth, xPosn, yPosn)
@native def drawLine(x1: Int, y1: Int, x2: Int, y2: Int): Unit
}
}
前两种方法工作正常,但内部类的本机方法提供
object XApp extends App
{
val xc:XCClass = XCClass()
val win: xc.Window = xc.Window(800, 600)
win.drawLine(20, 20, 40, 40)
readLine()
}
线程“main”中的异常java.lang.UnsatisfiedLinkError:pXClient.XCClass $ Window.drawLine(IIII)V
这是C ++签名
extern "C" JNIEXPORT void JNICALL Java_pXClient_XCClass$Window_drawLine(JNIEnv * env, jobject c1, Display *dpy,
Window win, jint x1, jint y1, jint x2, jint y2)
我尝试使用下划线代替$符号,并且根本没有内部名称,但也失败了。
Edit2:在看到Robin的回答之前,我设法让javah工作了,它给了
JNIEXPORT void JNICALL Java_pXClient_XCClass_00024Window_drawLine
(JNIEnv *, jobject, jint, jint, jint, jint);
Edit4:一旦我纠正了代码中的错误,它工作正常。只要名称正确,JVM似乎就会导入带有错误参数签名的本机函数。
答案 0 :(得分:6)
我刚刚使用.java
文件和javah
进行了快速测试,$
表示为_00024
。