yglukhov / jnim

Nim - Java bridge
MIT License
184 stars 13 forks source link

Only works on Mac OSX? #2

Closed wheineman closed 9 years ago

wheineman commented 9 years ago

This proc prevents any other OS from working:

proc linkWithJVMLib() =
    when defined(macosx):
        let libPath : cstring = "/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk"

        {.emit: """
        CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)`libPath`, strlen(`libPath`), true);
        CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, url);
        CFRelease(url);

        `JNI_CreateJavaVM` = CFBundleGetFunctionPointerForName(bundle, CFSTR("JNI_CreateJavaVM"));
        `JNI_GetDefaultJavaVMInitArgs` = CFBundleGetFunctionPointerForName(bundle, CFSTR("JNI_GetDefaultJavaVMInitArgs"));
        """.}
    else:
        assert(false, "Not implemented!")

I get this attempting to run your example:

$ testjnim Traceback (most recent call last) testjnim.nim(16) testjnim jnim.nim(413) newJavaVM jnim.nim(104) linkWithJVMLib system.nim(3058) failedAssertImpl system.nim(2280) raiseAssert Error: unhandled exception: false Not implemented! [AssertionError]

yglukhov commented 9 years ago

@wheineman, you're right. The linkage is done for macos only. Besides, the path to jni lib is hardcoded, while should be searched in runtime. The linkage for other platforms should be simpler, than on mac, using just loadLib and symAddr from dynlib module. Unfortunately, I can't test it on other platforms, but would gladly accept the PRs ;)

wheineman commented 9 years ago

Okay. Thanks for the heads up. I'll see what I can do for Windows and Linux.

yglukhov commented 9 years ago

fd32f2078c44b4434d697989d3e37201c83c0fea Should deal with other platforms, but I haven't tested it. Closing this issue for now. Please reopen if doesn't work.