This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

JNIEXPORT, JNICALL problems


All,

I am trying to call a Fortran90 routine from a java class using
JNIEXPORT and JNICALL from Linux..  

It looks like there is a problem in the calling protocol from c++ to
g95.  Please read the e-mail.

Should I be using a different compiler preprocessor macro rather than -D
_FORTRAN_BUILD?

Your assistance would be greatly appreciated.


Thanks,

Cliff

1).  The Fortran90 routine that I am trying to call in a java class has
the following definition:

subroutine APMCALC

I use the following command to make a shared object:

g95 -fPIC -fintrinsic-extensions -fcase-upper -r8 -shared -o
APMFortran.so apm_mod.f90 apmsubs.f90 apmcalc.f90

2).  The JNIEXPORT .h and .cpp files to export the fortran subroutine
APMCALC are:

.h

* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class APMCalcJava */


extern "C" {

/*
 * Class:     APMCalcJava
 * Method:    APMCALC
 * Signature: ()V
 */

JNIEXPORT void JNICALL Java_APMCalcJava_APMCALC
  (JNIEnv*, jobject);

}

.cpp

#include <jni.h>
#include "APMCalcJava.h"
//
//######################################################################
#####################
//               APMCalcJava.cpp
//######################################################################
#####################

extern "C" void APMCALC_(void);

JNIEXPORT void JNICALL Java_APMCalcJava_APMCALC
(JNIEnv *env, jobject obj)
{
APMCALC_();
}

The c files are also made into a shared object with:

c++ -fPIC -D _FORTRAN_BUILD_ -shared -o libAPMCalcJava.so APMFortran.so
APMCalcJava.cpp

3).  The java class that attempts to call APMCALC is:

package APMCalc;

import java.nio.charset.*;
import java.nio.*;

public class APMCalcJava implements Runnable
{
	public APMCalcJava()

    public void run()
    {

	System.out.println("Starting APM ...");
	
	APMCALC();

	System.out.println("Ending  APM ...");

   }

	public static void main(String args[])
	{
	//
	//create a APMCalcJava object instance
	//

	APMCalcJava APMRun = new APMCalcJava();

	APMRun.run();

	}

	public native void APMCALC();

	static
	{
		System.loadLibrary("APMCalcJava");
	}

}

I run the java class with the following command and get the error:

 java -classpath classes APMCalc.APMCalcJava
Starting APM ...
Exception in thread "main" java.lang.UnsatisfiedLinkError: APMCALC
        at APMCalc.APMCalcJava.APMCALC(Native Method)
        at APMCalc.APMCalcJava.run(APMCalcJava.java:42)
        at APMCalc.APMCalcJava.main(APMCalcJava.java:63)
[



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]