delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1999/04/01/19:29:25

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
From: "Isselmou Ould-Dellahy" <iod AT ccrl DOT mot DOT com>
Message-Id: <199904020002.SAA11002@eastern.ccrl.mot.com>
Subject: JNI C return NaN for float and double
To: cygwin AT sourceware DOT cygnus DOT com
Date: Thu, 01 Apr 1999 18:02:26 CST
X-Mailer: Elm [revision: 212.4]

Hi,

How can I make a JNI interfaced C code, compiled as a dll, return the right
double or float number to its java caller? In my case (see the simple
Mummit's HelloWorld modified example below) it works fine when the returned
type is char or short or long; but it returns a NaN in case of float or double.
I have cygwin-b20.1 and java 1.1.6

Please help!
Thank you
--
Isselmou Ould Dellahy

============================ The example ===================================

---------------------- HelloWorld.java -------------------
class HelloWorld {
    public native double displayHelloWorld();

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

---------------------- Main.java -------------------------

class Main {
    public static void main(String[] args) {
        HelloWorld h = new HelloWorld();
        double d = h.displayHelloWorld();
        System.out.println("zzzzzzzzzz " + d);
    }
}
---------------------- HelloWorldImp.c -------------------

#include <stdio.h>
#include <stdlib.h>
#include <jni.h>
#include "HelloWorld.h"

JNIEXPORT jdouble JNICALL 
Java_HelloWorld_displayHelloWorld (JNIEnv *env, jobject obj) 
{
  char *home;
  printf("Java JNI\n");
  home = getenv ("HOME");
  printf("HOME = %s\n", (home) ? home : "(NULL)");
  return 46.8;
}

---------------------- Makefile --------------------------

#
# Sample makefile to create Java JNI with Cygwin b20.1 tools. This *will not*
# work with Cygwin versions earlier than b20.1.
# 
# The only difference from creating a regular DLL is to supply a different
# entry point, __cygwin_noncygwin_dll_entry AT 12, since Java is an MSVC app.
#

CC = gcc 

DEBUG = -g -Wall
CFLAGS = $(DEBUG) 
CPPFLAGS = -I. -I$(JDK_ROOT)/include -I$(JDK_ROOT)/include/win32

JDK_ROOT = c:/jdk1.1.6

AS = as
DLLTOOL = dlltool
DLLWRAP = dllwrap

#
# Various targets to build.
#
DLL_NAME = hello.dll
DLL_EXP_DEF = hello.def

all: classes $(DLL_NAME)
	jre -cp /users/iod/hifem/etc/classes/visualrt.zip -cp . Main

classes :
	javac Main.java
	javah HelloWorld

#
# DLL related variables. These are used when building the DLL. See later.
#

# Some tools require special CPP macros when building a DLL (eg., _DLL etc).
# Here we don't need anything.

# DLL_CFLAGS = -DBUILDING_DLL=1 -D_DLL=1 
DLL_CFLAGS = 

# The default entry point defined by dllwrap is __cygwin_dll_entry AT 12 
# defined in libcygwin.a, but that's only appropriate for Cygwin apps,
# but since Java is a MSVC app, we need to provide a different entry
# point. Note the leading underscore and the trailing @12.
# The -s flag strips the DLL to shrink the size.

DLL_LDFLAGS = -Wl,-e,__cygwin_noncygwin_dll_entry AT 12 -s

# any extra libraries that your DLL may depend on.
DLL_LDLIBS = #-luser32

DLL_SRCS  = HelloWorldImp.c
DLL_OBJS  = $(DLL_SRCS:.c=.o)

###
#
# Making DLL
#
###

DLLWRAP_FLAGS = --output-def $(DLL_EXP_DEF) \
	--add-stdcall-alias \
	--driver-name $(CC) \
	$(IMAGE_BASE) $(X)

$(DLL_NAME): $(DLL_OBJS)
	$(DLLWRAP) $(DLLWRAP_FLAGS) -o $(DLL_NAME) \
	    $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# dependencies.
#

#
# default rules for building DLL objects. Note that client programs (ie.,
# the ones that *use* the DLL) have to be compiled without the DLL_CFLAGS
# flags.
#

.c.o:
	$(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) $<

# Note that we omit the $(DLL_CFLAGS) for client programs.
usedll.o: %o: %c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<

clean:
	-rm -f $(OBJS) $(DLL_OBJS) $(DLL_NAME) $(DLL_EXP_LIB) $(DLL_EXP_DEF) $(TESTPROGS) *.class *~ HelloWorld.h
---------------------- Makefile end ----------------------

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019