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..
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
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.
Ernest Friedman-Hill
,
author and iconoclast
staff
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.