From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Mickish To: Glen Fullmer-EGF002 Cc: gnu-win32@cygnus.com Subject: Re: dll, java, gcc, cygwin Date: Fri, 23 Oct 1998 00:05:00 -0000 Message-id: <362F5356.36BA95C0@cmu.edu> References: <199810211705.MAA23362@emerald.ccrl.mot.com> X-SW-Source: 1998-10/msg00686.html It might be related to name mangling. Try adding .def aliases in your larger example. I have to supply aliases in a .def file like the following for every native method I export from the DLL: EXPORTS Java_HelloWorld_displayHelloWorld=Java_HelloWorld_displayHelloWorld@8 dll_entry@12 The @8, @12, etc is four * the number of parameters in the function definition. This has something to do with telling the compiler how it should pop parameters off the stack when returning from a function. All JNI methods have at least two parameters -- an object representing the Java environment and the object whose method is being invoked. --Andrew Mickish Glen Fullmer-EGF002 wrote: > Hi, > > I thought others might be interested in this letter I sent to Mumit: > ----- > I tried using your dllwrap tool and method to create the JNI HelloWorld > example and it failed as it couldn't find the native routine in the library, > whereas Andrew Mickish's method: > > http://www.andrew.cmu.edu/~am2q/HelloWorld.zip > > worked fine for the HelloWorld code. Looking at the code I can't see any > glaring differences. His makefile uses the loader/dlltool/loader/dlltool > method. I tried using Andrew's example on a larger piece of code and it > behaves the same as yours, i.e. the library loads but it can't find the > routines within the library. Perhaps his can only load one routine? ;-) > Any hints? > > My environment is: > > Windows/NT on a dual processor pentium. > gcc -v = egcs-2.91.57 19980901 (egcs-1.1 release) (cygwin - B19) > binutils (2.7-B19) > dllhelpers-0.2.1 > > I had to set DLL_LDFLAGS = -Wl,-e,_dll_entry@12 to avoid errors. > > Your dllwrap method failed with: > > ============================Makefile================================ > > .SUFFIXES: .java > .SUFFIXES: .class > > DLL_OBJS = HelloWorldImp.o > > DLL_NAME = hello.dll > DLL_EXP_DEF = hello.def > DLL_EXP_LIB = libhello.a > DLLWRAP = dllwrap > DLLTOOL = dlltool > > JAVA_HOME=/jdk1.1.6 > > # Java Files > JSRCS = HelloWorld.java Main.java > > JLIBBIN = HelloWorldImp.o > > JOBS=$(JSRCS:.java=.class) > > DLLWRAP_FLAGS = --driver-name $(CC) --def $(DLL_EXP_DEF) > DLL_CFLAGS = -DBUILDING_DLL=1 > > # The default entry point defined by dllwrap is DllMain defined in > # dllinit.c. You can override that here by specifying it in DLL_LDFLAGS. > # (eg., -Wl,-e,_MyDllMain@12 -- note the leading underscore and the > # trailing @12). > DLL_LDFLAGS = -Wl,-e,_dll_entry@12 > > all: $(DLL_NAME) $(JOBS) $(JLIBBIN) > > $(DLL_NAME): $(DLL_OBJS) $(DLL_EXP_DEF) > $(DLLWRAP) $(DLLWRAP_FLAGS) -o $(DLL_NAME) \ > $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS) > > $(DLL_EXP_LIB): $(DLL_EXP_DEF) > $(DLLTOOL) --dllname $(DLL_NAME) --def $(DLL_EXP_DEF) \ > --oubput-lib $(DLL_EXP_LIB) > $(DLL_EXP_DEF): $(DLL_OBJS) > $(DLLTOOL) --export-all --output-def $@ $(DLL_OBJS) > > HelloWorldImp.o: HelloWorldImp.c HelloWorld.h > gcc -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/win32 -c HelloWorldImp.c > > .java.class: > $(JAVA_HOME)/bin/javac $*.java > > HelloWorld.h: HelloWorld.class > $(JAVA_HOME)/bin/javah HelloWorld > > clean: > rm -f *.class *.o core hello.dll* > > ==============================HelloWorld.java============================ > class HelloWorld { > public native void displayHelloWorld(); > > static { > System.loadLibrary("hello"); > } > } > > ==============================HelloWorldImp.c============================ > /* following for PC port */ > #define __int64 long > > #include > #include "HelloWorld.h" > #include > > JNIEXPORT void JNICALL > Java_HelloWorld_displayHelloWorld(JNIEnv *env, jobject obj) > { > printf("Hello world!\n"); > return; > } > ==============================Output===================================== > /jdk1.1.6/bin/javac HelloWorld.java > /jdk1.1.6/bin/javah HelloWorld > gcc -I/jdk1.1.6/include -I/jdk1.1.6/include/win32 -c HelloWorldImp.c > dlltool --export-all --output-def hello.def HelloWorldImp.o > dllwrap --driver-name gcc --def hello.def -o hello.dll \ > HelloWorldImp.o -Wl,-e,_dll_entry@12 > /jdk1.1.6/bin/javac Main.java > > /jdk1.1.6/bin/java Main > java.lang.UnsatisfiedLinkError: displayHelloWorld > at Main.main(Main.java:3) > > ========================================================================= > > Am I missing something here? (besides my sanity! ;-) > > Thanks, > > Glen > -- > Glen Fullmer,(847)538-3082, Mail: , > ******************************************************************************* > * "For a successful technology, reality must take precedence * > * over public relations, for Nature cannot be fooled." - Richard P. Feynman * > ******************************************************************************* > > - > For help on using this list (especially unsubscribing), send a message to > "gnu-win32-request@cygnus.com" with one line of text: "help". - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request@cygnus.com" with one line of text: "help".