Cannot run C program from Java using Cygwin

I found that the reason this cannot be done is that cygwin1.dll cannot be dynamically loaded, because it needs 4k of bottom stack bytes to be free when it's initializing - which might be a problem if it's being called from JNI.

There are some ways to overcome it; if you're looking for a solution, this post sums up nicely what needs to be done and this one can also be useful. I also found an explicit solution here.


add header file which was generated using javah in your c file

/* ctest.c */
#include "HelloWorld.h"
#include <jni.h>
#include <stdio.h>

JNIEXPORT void JNICALL Java_HelloWorld_helloFromC
(JNIEnv * env, jobject jobj)
{
printf("Hello from C!\n");
}

and run using

java -Djava.library.path=. HelloWorld

if it does not work than try

java HelloWorld

a much more detailed example is explained in this site