java/9577: Linker error for legal Java/CNI code if method parameters are reversed

rmathew@hotmail.com rmathew@hotmail.com
Wed Feb 5 04:36:00 GMT 2003


>Number:         9577
>Category:       java
>Synopsis:       Linker error for legal Java/CNI code if method parameters are reversed
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 05 04:36:01 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     rmathew@hotmail.com
>Release:        3.3
>Organization:
>Environment:
MinGW (Win98SE).
Independently confirmed on RedHat Linux 8.0 as well.
>Description:
I have a Java file "Foo.java" like so:
-------------------------- 8< -----------------------------
import java.io.File;

public class Foo {
  public native void bar( String[] s, File f);
//public native void bar( File f, String[] s);
  public static void main( String[] args) { /* Dummy */ }
}
-------------------------- 8< -----------------------------

and a C++ implementation file "snafu.cc" like so:
-------------------------- 8< -----------------------------
#include "Foo.h"
#include <java/io/File.h>

  void Foo::bar (jstringArray s, java::io::File* f) { /* Dummy */ }
//void Foo::bar (java::io::File* f, jstringArray s) { /* Dummy */ }
-------------------------- 8< -----------------------------

This set produces a linker "undefined reference" error
for the native method Foo::bar( ).

However, if I reverse the order of the parameters of this
method in both Foo.java and snafu.cc (as shown by the
commented lines) it works!

In the case where one gets the linker error, it seems that
there is a possible name mangling error:
-------------------------- 8< -----------------------------
/e/tmp > nm Foo.o |grep bar
         U __ZN3Foo3barEP6JArrayIPN4java4lang6StringEEPN4java2io4FileE

/e/tmp > nm snafu.o |grep bar
00000000 T __ZN3Foo3barEP6JArrayIPN4java4lang6StringEEPNS1_2io4FileE
-------------------------- 8< -----------------------------
>How-To-Repeat:
Save the two files as Foo.java and snafu.cc respectively.
Execute:

    gcj -C Foo.java
    gcjh Foo
    gcj --main=Foo Foo.java snafu.cc

(the same error is produced even if I link the object files
separately)
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Java-prs mailing list