This is the mail archive of the cygwin mailing list for the Cygwin 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]

Re:JNI and cygwin


I need terminal and ncurses support and I have a JNI
layer that interacts with
 "curses" functions.The JNI wrapper needs to be built
into a shared library.
I have problems using the cygwin libraries with Java
VM.

I have a smaller example that can reproduce the
issue...

The shared library when compiled with the -mno-cygwin
option works without any
issues, however, when I remove this option, the
compilation goes fine, but when
I try and run the java program the VM hangs. This
issue has been reported
earlier. Has this problem been fixed?

I need to use the "cygwin" libraries for getting
"curses" support.

Command line used...

gcc  -mno-cygwin -Wl,--add-stdcall-alias -DCYGWIN_MODE
-shared -o myfunction.dll
 -Ic:/j2sdk1.4.2_06/include 
-Ic:/j2sdk1.4.2_06/include/win32 myfunction.c

Venkatesh.


/**** HEADER FILE tryloading.h ****/

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

#ifndef _Included_tryloading
#define _Included_tryloading
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     tryloading
 * Method:    myfunction
 * Signature: (Ljava/lang/String;)I
 */
JNIEXPORT jint JNICALL Java_tryloading_myfunction
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus
}
#endif
#endif

/***** C CODE ******/

#include "tryloading.h"

#include <stdlib.h>
#include <stdio.h>


int __stdcall _cygwin_dll_entry(void* h,int
reason,void *foo)
{
	
	return 1;
}




JNIEXPORT jint JNICALL Java_tryloading_myfunction
  (JNIEnv *myenv, jobject obj, jstring arg)
{
	
const char *argutf  =
(*myenv)->GetStringUTFChars(myenv, arg, JNI_FALSE);
 
    /* Call into external dylib function */
 
    jint rc = shared_function(argutf);
 
 
    /* Release created UTF8 string. */
 
    (*myenv)->ReleaseStringUTFChars(myenv, arg,
argutf);
 
	shared_function("hello world");
 
    return rc;
}

int shared_function(const char *arg) {
 
 
    printf("shared_function called with %s\n", arg);
 
 
    return 42;
 
 
}
 



/***** JAVA CODE *****/
public class tryloading
{
	static
	{	
		System.out.println("before loading");
		try
		{
		System.loadLibrary("myfunction");
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}

	public tryloading()
	{
		System.out.println("instance created");
	}

	native int myfunction(String arg);

	public static void main(String args[])
	{
		System.out.println("in main");

		tryloading tl = new tryloading();
		int result = tl.myfunction("hello world");
		
		System.out.println("Finished wrapper " + result);

		
	}
	
}


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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