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

I have a smaller example that can reproduce the

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/win32 myfunction.c


/**** 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" {
 * Class:     tryloading
 * Method:    myfunction
 * Signature: (Ljava/lang/String;)I
JNIEXPORT jint JNICALL Java_tryloading_myfunction
  (JNIEnv *, jobject, jstring);

#ifdef __cplusplus

/***** 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,
	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
		System.out.println("before loading");
		catch(Exception e)

	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 

Unsubscribe info:
Problem reports:

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