Friday, February 25, 2011

4. Create a Stubs File

In addition to the .h file that you generated in the previous step, you must also use javah to generate a stub file. The stub file contains C code that provides the glue that holds the Java class and its parallel C structure together. To generate a stub file use javah's -stubs option. Again remember to run javah on the Java class.
By default, javah will place the resulting stub file in the same directory as the .class file. You can use the -d option to force javah to put the generated stub file in a different directory.
Similar to the .h file that javah generates, the name of the stubs file is the class name with .c appended to the end. In the "Hello World!" example that you've been working with throughout this lesson, the stub file is called HelloWorld.c : 

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <StubPreamble.h>

/* Stubs for class HelloWorld */
/* SYMBOL: "HelloWorld/displayHelloWorld()V", Java_HelloWorld_displayHelloWorld_stub */
stack_item *Java_HelloWorld_displayHelloWorld_stub(stack_item *_P_,struct execenv *_EE_) {
 extern void HelloWorld_displayHelloWorld(void *);
 (void) HelloWorld_displayHelloWorld(_P_[0].p);
 return _P_;
}

For the moment, all you really need to know about the stub file is that you will later compile it into the dynamically loadable library that you create in Step 6: Create a Dynamically Loadable Library.

No comments:

Post a Comment

Chitika