↑ ↓ ← → Will Senn <Will_member pathlink.com>
writes:
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
↑ ↓ ← → Scott Michel <scottm aero.org>
writes:
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
↑ ↓ ← → Will Senn <Will_member pathlink.com>
writes:
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
↑ ↓ ← → Scott Michel <scottm aero.org>
writes:
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.
↑ ↓ ← → Will Senn <wsenn cc.admin.unt.edu>
writes:
Scott Michel wrote:
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.
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,
Will
↑ ↓ ← → Scott Michel <scottm aero.org>
writes:
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.
↑ ↓ ← → Will Senn <wsenn cc.admin.unt.edu>
writes:
Scott Michel wrote:
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.
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,
Will
↑ ↓ ← → Scott Michel <scottm aero.org>
writes:
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.
↑ ↓
← → Jan Knepper <jan smartsoft.us>
writes:
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
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