Hello World in JNI

M

maurizio

I'am very bad working with program but I love java programming and i want to
make my first program in JNI but I have a big trouble in this part of the
process.

This is the part of the java tutorial explains the way to build the .dll
**********
On Win32, the following command builds a dynamic link library hello.dll
using Microsoft Visual C++ 4.0:

cl -Ic:\java\include -Ic:\java\include\win32
-LD HelloWorldImp.c -Fehello.dll

Of course, you need to specify the include path that corresponds to the
setup on your own machine.
*************
I dont't understand the first line of the code and what means include is the
setup on my own machine. The set up of what machine?
I have not Microsoft Visual C++ 4.0 in my Windows 98.
I have only Microsoft.VisualC.Dll in my machine but I don't know if it's the
same

I don't understand why the name of the lib is -Fehello.dll


Could someone help me?


Regard Maurizio
 
M

Marco Parmeggiani

I dont't understand the first line of the code and what means include is the
setup on my own machine. The set up of what machine?

your machine. you need to provide paths to <path of jdk>/include and
I have not Microsoft Visual C++ 4.0 in my Windows 98.

if you want to compile C source code to use with Java via JNI you have
to install a C compiler.
I don't understand why the name of the lib is -Fehello.dll

you should look at the documentation of the microsoft visual c++
compiler to understand that parameter. The example for windows is
written using that compiler.

ciao
 
J

Joerg Gippert

Hi Maurizio,
I'am very bad working with program but I love java programming and i want to
make my first program in JNI but I have a big trouble in this part of the
process.

This is the part of the java tutorial explains the way to build the .dll
**********
On Win32, the following command builds a dynamic link library hello.dll
using Microsoft Visual C++ 4.0:

cl -Ic:\java\include -Ic:\java\include\win32
-LD HelloWorldImp.c -Fehello.dll

Of course, you need to specify the include path that corresponds to the
setup on your own machine.
*************
I dont't understand the first line of the code and what means include is the
setup on my own machine. The set up of what machine?
I have not Microsoft Visual C++ 4.0 in my Windows 98.
I have only Microsoft.VisualC.Dll in my machine but I don't know if it's the
same

I don't understand why the name of the lib is -Fehello.dll

I never used VC++ 4.0. That´s a quite old version.I´m using VC++6.0 or VC++
..NET (don´t booh at me newsgroup - it´s just the name .Net ;) ) I guess the
name Fehello comes from some makefile. In order to create your own DLL, you
will need a C/C++ compiler installed on your system. The runtime DLL of MSVC
won´t help you much. There´s a quite good JNI tutorial at Sun´s website you
might want to have a look at.

Regards,
Joerg
 
R

Roger Irwin

JNI is for calling routines you have developed in C. When compiling the
C program file (called HelloWorldImp.c), it needs to be linked with some
java libraries (which is what is on the first line), then the output
file generated is hello.dll.

Basically, these are instructions for created a C program that can be
called from Java, if you are not familiar with this I suggest you do not
try using the JNI. First learn Java programming, then C programming,
THEN try and put it together.

At the end of the day JNI is generally required only for specialist uses
such as implementing custom DSP filters in multemedia apps. For the most
part you should be able to find excellent implementations that allready
exist!
 
J

Joseph Millar

I'am very bad working with program but I love java programming and i want to
make my first program in JNI but I have a big trouble in this part of the
process.

This is the part of the java tutorial explains the way to build the .dll
**********
On Win32, the following command builds a dynamic link library hello.dll
using Microsoft Visual C++ 4.0:

cl -Ic:\java\include -Ic:\java\include\win32
-LD HelloWorldImp.c -Fehello.dll

Of course, you need to specify the include path that corresponds to the
setup on your own machine.
*************
I dont't understand the first line of the code and what means include is the
setup on my own machine. The set up of what machine?

-I tells the MS compiler where to find header files. In this
case the instructions are telling you to tell the compiler
where your jni.h header is (along with others). jni.h is
provided by the JDK in the JDK's include directory, but since
they (the tutorial's authors) have no idea where you installed
your JDK, they are just telling your to supply the path that is
correct for your local setup.
I have not Microsoft Visual C++ 4.0 in my Windows 98.

You will need a valid C compiler for Win32. While the tutorial
uses Visual C++ 4.0, any compiler capable of creating a DLL can
be used, but you will have to supply equivalent commands. I
use Visual C++ 6.0 and the commands are the same.
I have only Microsoft.VisualC.Dll in my machine but I don't know if it's the
same

No idea what you're saying here.
I don't understand why the name of the lib is -Fehello.dll

-Fe is simply the option that tells the compiler what the name
of the created module should be. It's used very commonly to
force a particular name that is different from the one the
compiler would choose by default. In this case, the dll
created will be called "hello.dll". If the -Fe option had
not been provided, the name would have been "HelloWorldImp.dll"

I get the feeling you are not familar with C or C++ from your
post. If that's true you should do some basic learning on
how to propgram in C and C++ and how to use the various tools
provided by your compiler. FOrgive me if I'm wrong.

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top