This is the mail archive of the java-prs@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]