- UNIX
% cc -G HelloWorld.c HelloWorldImp.c -o libhello.so
Note: You may need to use the-I
flag to indicate to the compiler where to find the various header files. For examplecc -G -I$JAVAHOME/include -I$JAVAHOME/include/solaris HelloWorld.c HelloWorldImp.c -o libhello.sowhere$JAVAHOME
is the directory where you installed the Java release. The C compiler will create a filelibhello.so
in the current directory.
- DOS shell (Windows 95/NT)
C:\> cl HelloWorld.c HelloWorldImp.c -Fehello.dll -MD -LD javai.libNote: You must have Microsoft Visual C++ Version 2.x to compile and link DLLs (Dynamic Link Libraries).Note:
javai.lib
must be the last argument to the C compiler.Note: To inform the compiler of the location of the Java C header files, add
%JAVAHOME%\include
to the environment variableINCLUDE
:C:\> set INCLUDE=%JAVAHOME%\include;%INCLUDE%Note: To inform the linker of the location of the Java libraries, add
%JAVAHOME%\lib
to the environment variableLIB
:C:\> set LIB=%JAVAHOME%\lib;%LIB%