Help request from newbee on JvNewTYPEArray and System.out usage

mirleau@bluewin.ch mirleau@bluewin.ch
Sun May 14 17:01:00 GMT 2006


Hi, I'm trying to call java from a c++ main(),I managed get this far:

===========================================================

[mirleau@astrid learngcj]$ gcj --version
gcj (GCC) 4.1.0 20060304 (Red Hat 4.1.0-3)
[mirleau@astrid learngcj]$ cat Class1.java
public class Class1
{
    public double doIt(double anInput)
    {
        return anInput + 1.4;
    }
}
[mirleau@astrid learngcj]$ cat Class1.cc
#include "Class1.h"
#include <stdio.h>

main()
{
  Class1 myC1Object;
  double myInput = 122.;
  double myOutput =  (double) myC1Object.doIt((jdouble) myInput);
  printf("Output: %f\n", myOutput);
}
[mirleau@astrid learngcj]$ make Class1.exe
gcj -C Class1.java
gcjh Class1 --classpath=.
gcj -c -fPIC Class1.java
gcc -lgcj -fPIC Class1.o Class1.cc -o Class1.exe
rm Class1.o Class1.class Class1.h
[mirleau@astrid learngcj]$ ./Class1.exe
Output: 123.400000

===============================================================

OK, everything seems fine, however I'm having some trouble getting further:

If I try to pass array arguments I get a Floating point exception,
which seems to be unrelated to any java files:

===============================================================

[mirleau@astrid learngcj]$ cat Class2.cc
#include <gcj/array.h>
#include <stdio.h>

main()
{
  jbooleanArray myInputArray = NULL;

  printf("Was here1\n"); fflush(stdout);
  myInputArray = JvNewBooleanArray((jint) 2);
  printf("Was here2\n"); fflush(stdout);
}
[mirleau@astrid learngcj]$ gcc -lgcj -fPIC Class2.cc -o Class2.exe
[mirleau@astrid learngcj]$ ./Class2.exe
Was here1
Floating point exception

===============================================================

Problem two I get if I use System.out.println in the java class:

===============================================================

[mirleau@astrid learngcj]$ cat Class3.java
public class Class3
{
    public double doIt(double anInput)
    {
        System.out.println("abc");
        return anInput + 1.4;
    }
}
[mirleau@astrid learngcj]$ cat Class3.cc
#include "Class3.h"
#include <stdio.h>

main()
{
  Class3 myC3Object;
  double myInput = 122.;
  double myOutput =  (double) myC3Object.doIt((jdouble) myInput);
  printf("Output: %f\n", myOutput);
}
[mirleau@astrid learngcj]$ make Class3.exe
gcj -C Class3.java
gcjh Class3 --classpath=.
gcj -c -fPIC Class3.java
gcc -lgcj -fPIC Class3.o Class3.cc -o Class3.exe
rm Class3.class Class3.h Class3.o
[mirleau@astrid learngcj]$ ./Class3.exe
Segmentation fault

=============================================================

I also tried on an older version of gcc (3.3.3), but that doesn't help,
I must be doing something wrong here,
If anybody can help me out it would be appreciated!

Ciao, Olivier



More information about the Gcc-help mailing list