c++.windows.32-bits - JNI and the DMc compiler
- Will Senn (61/61) Jun 16 2006 Hi,
- Scott Michel (2/80) Jun 19 2006
- Will Senn (4/84) Jun 19 2006 printf("Hello world!\n");
- Scott Michel (3/7) Jun 20 2006 Ok, so you're only using stdio. Make sure you're using the DLL runtime
- Will Senn (7/15) Jun 21 2006 Scott,
- Scott Michel (5/8) Jun 21 2006 "-ND" to the compiler. That causes the compiler to insert a library
- Will Senn (19/29) Jun 22 2006 Hmmm... Seems like this option needs SND.lib, which is purportedly only
- Scott Michel (5/17) Jul 12 2006 Sounds like you use DM for a lot more than just this project.
- Jan Knepper (9/9) Jun 19 2006 Attached some code I wrote some years ago to export the Window Address
Hi, I am having trouble building a dll that java can use jni on, seems to build fine, but then just hangs and hangs and hangs... Here's the c: -- -- hello.c -- #include <jni.h> #include "HelloWorld.h" #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf("Hello world!\n"); return; } -- -- HelloWorld.h is a generated file (java gen's it) -- #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif Here is the compile command that I gave dmc: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib There are no errors displayed and a dll is created. However, when I try to do the java trick (which works with ms compiler created dll's), it hangs. Here's th e java stuff, in case you want to see :) --HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } compile the java byte code: javac -classpath . HelloWorld.java generate the HelloWorld.h file: javah -jni -classpath . HelloWorld compile the dll: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib execute the java app: java -classpath . HelloWorld Any help would be greatly appreciated. Thanks, Will
Jun 16 2006
Wouldn't happen to be doing iostream calls, would you? Will Senn wrote:Hi, I am having trouble building a dll that java can use jni on, seems to build fine, but then just hangs and hangs and hangs... Here's the c: -- -- hello.c -- #include <jni.h> #include "HelloWorld.h" #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf("Hello world!\n"); return; } -- -- HelloWorld.h is a generated file (java gen's it) -- #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif Here is the compile command that I gave dmc: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib There are no errors displayed and a dll is created. However, when I try to do the java trick (which works with ms compiler created dll's), it hangs. Here's th e java stuff, in case you want to see :) --HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } compile the java byte code: javac -classpath . HelloWorld.java generate the HelloWorld.h file: javah -jni -classpath . HelloWorld compile the dll: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib execute the java app: java -classpath . HelloWorld Any help would be greatly appreciated. Thanks, Will
Jun 19 2006
printf("Hello world!\n"); return; is the only code in the called dll. In article <e76k2s$1hb7$1 digitaldaemon.com>, Scott Michel says...Wouldn't happen to be doing iostream calls, would you? Will Senn wrote:Hi, I am having trouble building a dll that java can use jni on, seems to build fine, but then just hangs and hangs and hangs... Here's the c: -- -- hello.c -- #include <jni.h> #include "HelloWorld.h" #include <stdio.h> JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) { printf("Hello world!\n"); return; } -- -- HelloWorld.h is a generated file (java gen's it) -- #include <jni.h> /* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif /* * Class: HelloWorld * Method: displayHelloWorld * Signature: ()V */ JNIEXPORT void JNICALL Java_HelloWorld_displayHelloWorld (JNIEnv *, jobject); #ifdef __cplusplus } #endif #endif Here is the compile command that I gave dmc: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib There are no errors displayed and a dll is created. However, when I try to do the java trick (which works with ms compiler created dll's), it hangs. Here's th e java stuff, in case you want to see :) --HelloWorld.java class HelloWorld { public native void displayHelloWorld(); static { System.loadLibrary("hello"); } public static void main(String[] args) { new HelloWorld().displayHelloWorld(); } } compile the java byte code: javac -classpath . HelloWorld.java generate the HelloWorld.h file: javah -jni -classpath . HelloWorld compile the dll: dmc -I C:\jdk1.5.0_07\include;C:\jdk1.5.0_07\include\win32 -mn -WD hello.c kernel32.lib execute the java app: java -classpath . HelloWorld Any help would be greatly appreciated. Thanks, Will
Jun 19 2006
Will Senn wrote:printf("Hello world!\n"); return; is the only code in the called dll.Ok, so you're only using stdio. Make sure you're using the DLL runtime and not the statically linked DMC runtime. Will require a recompile.
Jun 20 2006
Scott Michel wrote:Will Senn wrote:Scott, What do you mean by "DLL runtime and not he statically linked DMC runtime"? or rather, how do I ensure that this is the case - is it a paramter to the compiler or what? Thanks, Willprintf("Hello world!\n"); return; is the only code in the called dll.Ok, so you're only using stdio. Make sure you're using the DLL runtime and not the statically linked DMC runtime. Will require a recompile.
Jun 21 2006
Will Senn wrote:What do you mean by "DLL runtime and not he statically linked DMC runtime"? or rather, how do I ensure that this is the case - is it a paramter to the compiler or what?"-ND" to the compiler. That causes the compiler to insert a library record into the object file that picks up the DLL version of the compiler runtime. http://www.digitalmars.com/ctg/ctg.html will always be your friend.
Jun 21 2006
Scott Michel wrote:Will Senn wrote:Hmmm... Seems like this option needs SND.lib, which is purportedly only available on the CD, which costs 40+ bucks. I verified that this works in MS. I downloaded VC++ 2005 Express Edition and built the dll using: cl -IC:\jdk1.5.0_07\include -IC:\jdk1.5.0_07\include\win32 -LD hello.c -Fehello.dll the dll that resulted worked flawlessly with jni... I would prefer to use Digital Mars, but I'm not excited about paying for a CD just to 'see' if my program will compile and run. Is there not a way to build this incredibly simplistic example of a dll using the downloadable version of dmc? The cl options are: -I include dir -LD create dll -Fe name output executable That's it, no bizarre options, just build a dll and name it hello.dll. Thanks, WillWhat do you mean by "DLL runtime and not he statically linked DMC runtime"? or rather, how do I ensure that this is the case - is it a paramter to the compiler or what?"-ND" to the compiler. That causes the compiler to insert a library record into the object file that picks up the DLL version of the compiler runtime. http://www.digitalmars.com/ctg/ctg.html will always be your friend.
Jun 22 2006
Will Senn wrote:Hmmm... Seems like this option needs SND.lib, which is purportedly only available on the CD, which costs 40+ bucks.<sarcasm>And this is some incredible hardship?</sarcasm>I verified that this works in MS. I downloaded VC++ 2005 Express Edition and built the dll using: cl -IC:\jdk1.5.0_07\include -IC:\jdk1.5.0_07\include\win32 -LD hello.c -Fehello.dll the dll that resulted worked flawlessly with jni... I would prefer to use Digital Mars, but I'm not excited about paying for a CD just to 'see' if my program will compile and run.Sounds like you use DM for a lot more than just this project. In the past, '-ND' was the way I went about making JNI work. Static libraries don't work well, esp. stdio or iostreams are involved.
Jul 12 2006
Attached some code I wrote some years ago to export the Window Address BooK (WAB) from Java via JNI. Hope this helps. Jan -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Jun 19 2006