Arguments to native functions (?) [a bit long]

Simon Gornall simon@unique-id.com
Mon Jun 28 07:34:00 GMT 1999


I'm not sure I quite believe this is a problem, since I'd expect
it to have been caught before now, but it seems to be the case
on my system (I've just re-checked out the library)
Anyway, if I call a native function with more than 3 arguments
I get a compile-time error saying the linker can't find the
native function.
Here's the example test cases: The first one passes 5 arguments,
the second passes three - that's the only difference, and the
second piece of code works fine...
================================================================
This doesn't work:
================================================================
test.java:
----------
public class test
 {
 // Constructor
 public test()
 {
 String t = "hi there";
 int y = ctest(t,4,t,t,t);
 System.err.println(y);
 }
 public static void main(String args[])
 {
 test t = new test();
 }
 // test native interface
 public int ctest(String a, int num, String b,
 String x, String y)
 {
 return calltest(a,num, b, x, y);
 }
	
 public native int calltest(String a, int num, String b,
 String x, String y);
 }
nTest.cc:
---------
#include <cni.h>
#include "test.h"
// Native interface to the Database connection method
jint test::calltest(jstring a, jint v, jstring b,
 jstring x, jstring y)
 {
 return v;
 }
[simon@donerkebab test]$ gcj -c test.java
[simon@donerkebab test]$ gcj -C test.java
[simon@donerkebab test]$ gcjh test
[simon@donerkebab test]$ g++ -c -fno-rtti -I/opt/egcs/include/java
 nTest.cc
[simon@donerkebab test]$ gcj -o ttt test.o nTest.o --main=test
test.o: In function `test::ctest(java::lang::String *,
 int, java::lang::String *, java::lang::String *,
 java::lang::String *)':
/usr/people/Simon/Source/Monitor/server/test/test.java(.data+0xfc):
 undefined reference to `test::calltest(java::lang::String *,
 int, java::lang::String *, java::lang::String *,
 java::lang::String *)'
test.o: In function `global constructors keyed to test::test(void)':
/usr/people/Simon/Source/Monitor/server/test/test.java(.data+0x120):
 undefined reference to `test::calltest(java::lang::String *,
 int, java::lang::String *, java::lang::String *,
 java::lang::String *)'
collect2: ld returned 1 exit status
================================================================
Whereas this works fine
================================================================
test.java:
----------
public class test
 {
 // Constructor
 public test()
 {
 String t = "hi there";
 int y = ctest(t,4,t);
 System.err.println(y);
 }
 public static void main(String args[])
 {
 test t = new test();
 }
 // test native interface
 public int ctest(String a, int num, String b)
 {
 return calltest(a,num, b);
 }
	
 public native int calltest(String a, int num, String x);
 }
nTest.cc:
---------
#include <cni.h>
#include "test.h"
// Native interface to the Database connection method
jint test::calltest(jstring a, jint v, jstring b)
 {
 return v;
 }
And it returns the following when run:
[simon@donerkebab test]$ gcj -c test.java
[simon@donerkebab test]$ gcj -C test.java
[simon@donerkebab test]$ gcjh test
[simon@donerkebab test]$ g++ -c -fno-rtti -I/opt/egcs/include/java
 nTest.cc
[simon@donerkebab test]$ gcj -o ttt test.o nTest.o --main=test
[simon@donerkebab test]$ ./ttt
4


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /