Linking mkl functions with JAVA

Linking mkl functions with JAVA


Please give me the details of how to link the mkl functions with JAVA.

Is there any setting option in JAVA to include the files "mkl_c.lib" and "libguide.lib"?

Or the procedure for calling mkl functions from JAVA is different compared to VC++?



3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.


Are you asking about Suns Java and its ports? If so, then basically, yes, the way to call MKL functions from Java is different.

Java implementations deem MKL as native code which is distinguished from Java bytecode. For calling native code from Java bytecode, Java supports the so-called Java Native Interface (JNI). You may read about JNI at the Suns web-site:

Roughly speaking, one needs to know three points about the JNI:

  • The keyword native of the Java Language which is used to mark stub methods.
  • The javah tool found inside JDK which is used to generate *.h files for the stubs.
  • Understand what the stubs are.

To simplify the get started stage of studying JNI, you may want to see the codes for the example Hello World! application which Im displaying hereby. Hopefully, this must help.


Yevgeny Latkin

Files list:

  • setup.bat
  • makefile
  • hello.c

File listings:

File: setup.bat

set JAVA_HOME=C:injdk1.6


call "C:Program FilesMicrosoft Visual Studio 8VCvcvarsall.bat"

File: makefile


@echo # Usage: nmake {all/clean} [CC=icl]

@echo #

@echo # CC=icl - use Intel C++ compiler


CC = cl


.PHONY: all clean


@echo # compile the Java code


@echo # create *.h for the stubs

javah hello

@echo # build the stubs library

$(CC) /LD /Fehello.dll hello.c /I.

/I$(JAVA_HOME)include /I$(JAVA_HOME)includewin32

@echo # remove needless files

del hello.obj

del hello.lib

del hello.exp

del hello.h

@echo # run the Java application

java -Djava.library.path=. hello

@echo # OK


-del hello.dll

-del Hello.class



* Demonstrating JNI.


public final class hello {


* Command-line options args[] ignored.


public static void main(String args[]) {




* Stub method.


private static native void hello();


* Load the stubs library.


static {




File: hello.c

#include "hello.h"




* Class: hello

* Method: hello

* Signature: ()V


JNIEXPORT void JNICALL Java_hello_hello(JNIEnv *env, jclass clazz) {



This article was very helpful.

Moving one step ahead, could you please suggest some example with makefile where JAVA is calling fortran with JNI as wrapper.

Thanks a lot in advance!!

Leave a Comment

Please sign in to add a comment. Not a member? Join today