Forums Register Login

JNI error

+Pie Number of slices to send: Send
I followed the JNI tutorial and why everytime I use a gcc compiler to generate a dll in windows, I got the following error.



Kind regards,
Jiafan
+Pie Number of slices to send: Send
The gcc I am using now is:


I wonder if the gcc is compatiable with the JNI interface.

Regards,
Jiafan
+Pie Number of slices to send: Send
I also downloaded the MS cl compiler and still does not work with the following exception.



Since in the basic c file I was writing, it definately includes the printf..so a stdio.h is definately used..why it complains about the stdio.h not found..

I love Java more than others.

Regards,
Jiafan
+Pie Number of slices to send: Send
Try hardcoding the include statement to where the ".h" file is. For example:

#include <D:\blah\blah\stdio.h>

(You may have to do this for other ones as well)
+Pie Number of slices to send: Send
I fixed the stdio.h problem by explicitly add a set inthe AUTOEXEC.bat..

but I still have the problem when I link the object file into a dll...



Jiafan
[ September 18, 2006: Message edited by: Jiafan Zhou ]
+Pie Number of slices to send: Send
I think I fixed the problem with the CL compiler..well I stll have a fatal problem at last..



Do I need to setup a LD_LIBRARY_PATH Environment Variable?( I have created one where I located my dll and exp files)

Regards,
Jiafan
+Pie Number of slices to send: Send
LD_LIBRARY_PATH is a Unix thing only.

Use the -Djava.library.path=<path> Java command-line switch.
+Pie Number of slices to send: Send
1- When using gcc you must add the following compiler/linker flags:

-D__int64="long long"
-shared
-Wl,--add-stdcall-alias

So that your command line should look like:

gcc -D__int64="long long" -I"C:\jdk1.5.0_06\include" -I"C:\jdk1.5.0_06\include\win32" -shared -Wl,--add-stdcall-alias -o hello.dll HelloWorldImp.c

Also if your are using gcc under Cygwin you should also use the flag -mno-cygwin to be able to run your program outside Cygwin.


2- When using MS cl.exe and link.exe you should allways first call vcvars32.bat located in the MSVC bin folder
(C:\Program Files\Microsoft Visual Studio 8\VC\bin for instance).
This script sets all the necessary variables to the appropriate values.
There is albsolutely NO NEED to set anything by hand.
And I wouln't call it in autoexec.bat since this will load your system/user environment at any time,
even when you are not building c/c++ files.


3- When you have successfully build your DLL you should either:
a- Put it in a folder already pointed by the Path enviroment variable (usually not a good idea)
b- Update the Path enviroment variable to add the folder where your DLL is located.
You could do that each time just before executing the Java program:
>set Path=yourDllFolder;%Path%
>java YourClass
You could also update your Path enviroment variable once and for all with the help of the 'System Properties' window.
c- (Preferably) Set the folder of your DLL while executing your Java program with the java.library.path property:
> java -Djava.library.path=yourDllFolder YourClass


Regards
+Pie Number of slices to send: Send
I still have the following error..


Regards,
Jiafan
+Pie Number of slices to send: Send
It works...

I made a silly mistake in the C program which does not make the function signature same in the .h file.

I will post the c program in a second for others to track the errors.


Notice that I used the fully qualified package modifier here, I ignored this for the first time and it ends up with errors in the runtime.

Thanks guys very much for the help.
[ September 19, 2006: Message edited by: Jiafan Zhou ]
+Pie Number of slices to send: Send
 

Originally posted by Jean-Francois Briere:
1- When using gcc you must add the following compiler/linker flags:

-D__int64="long long"
-shared
-Wl,--add-stdcall-alias

So that your command line should look like:

gcc -D__int64="long long" -I"C:\jdk1.5.0_06\include" -I"C:\jdk1.5.0_06\include\win32" -shared -Wl,--add-stdcall-alias -o hello.dll HelloWorldImp.c

Also if your are using gcc under Cygwin you should also use the flag -mno-cygwin to be able to run your program outside Cygwin.


2- When using MS cl.exe and link.exe you should allways first call vcvars32.bat located in the MSVC bin folder
(C:\Program Files\Microsoft Visual Studio 8\VC\bin for instance).
This script sets all the necessary variables to the appropriate values.
There is albsolutely NO NEED to set anything by hand.
And I wouln't call it in autoexec.bat since this will load your system/user environment at any time,
even when you are not building c/c++ files.


3- When you have successfully build your DLL you should either:
a- Put it in a folder already pointed by the Path enviroment variable (usually not a good idea)
b- Update the Path enviroment variable to add the folder where your DLL is located.
You could do that each time just before executing the Java program:
>set Path=yourDllFolder;%Path%
>java YourClass
You could also update your Path enviroment variable once and for all with the help of the 'System Properties' window.
c- (Preferably) Set the folder of your DLL while executing your Java program with the java.library.path property:
> java -Djava.library.path=yourDllFolder YourClass


Regards



This is an awesome post and I vote for it as one of the best/most informative posts ever.

It raises the question, however, as to why Sun's JNI tutorial doesn't mention any of this.
+Pie Number of slices to send: Send
 

Originally posted by Dan Bizman:

It raises the question, however, as to why Sun's JNI tutorial doesn't mention any of this.



Because some of it is subjective opinion, and its validity depends on some unstated assumptions about versions of various things. Not saying it's not useful, but for some folks this recipe wouldn't work.

Note that Sun's JNI tutorial ain't there anymore -- I'd guess because providing compiler recipes which worked for everyone was getting too tricky.
+Pie Number of slices to send: Send
I cant agree more.

Jiafan
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 7716 times.
Similar Threads
Problem running C++ implementaion in Netbeans 6.8 (cygwin compiler)
regarding cc compiler in linux ... i get an error
system/cpu usage in linux..plz help..
"jni_md.h: No such file or directory"- Error Message while compiling C source code
JNI Problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 16:51:42.