Segfault on simple HelloWorld
James CE Johnson
jcej@tragus.org
Thu Mar 23 18:49:00 GMT 2000
Forgive the newcomer...
I'm interested in using Java classes from my C++ app. I just tripped
across gcj a few weeks ago & started messing with it. The simple test
case I have below segfaults.
[jcej@node04 tmp]$ cat Makefile
INCLDIR = -I
$(HOME)/ThirdParty/objdir/i686-pc-linux-gnu/libjava/include
INCLDIR += -I $(HOME)/ThirdParty/libgcj-2.95.1/libjava/include
INCLDIR += -I $(HOME)/ThirdParty/libgcj-2.95.1/libjava
run : Test
LD_LIBRARY_PATH=/usr/local/lib ./Test
gdb : Test
LD_LIBRARY_PATH=/usr/local/lib gdb ./Test
Test : main.o Test.o
gcj -o Test main.o Test.o
main.o : main.cpp Test.h
g++ $(INCLDIR) -c main.cpp
Test.class : Test.java
javac -classpath . Test.java
Test.h : Test.class
gcjh --classpath . Test
Test.o : Test.class
gcj -c Test.class
clean realclean :
rm -f Test.o main.o Test.h Test.class Test
[jcej@node04 tmp]$ cat main.cpp
#include "Test.h"
int main(int,char**)
{
Test * test = new Test();
test->HelloWorld(); // This is line 8
delete test;
return 0;
}
[jcej@node04 tmp]$ cat Test.java
public class Test
{
public int HelloWorld()
{
System.out.println("Hello World");
return 0; // This is line 7
}
}
[jcej@node04 tmp]$ make gdb
javac -classpath . Test.java
gcjh --classpath . Test
g++ -I /home2/jcej/ThirdParty/objdir/i686-pc-linux-gnu/libjava/include
-I /home2
/jcej/ThirdParty/libgcj-2.95.1/libjava/include -I
/home2/jcej/ThirdParty/libgcj-
2.95.1/libjava -c main.cpp
gcj -c Test.class
gcj -o Test main.o Test.o
LD_LIBRARY_PATH=/usr/local/lib gdb ./Test
GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you
are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for
details.
This GDB was configured as "i586-pc-linux-gnu"...
(gdb) run
Starting program: /home2/jcej/tmp/./Test
Hello World
Program received signal SIGSEGV, Segmentation fault.
0x400b3844 in java::lang::Thread::interrupted ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/lang/Thread.java:276
276 }
Current language: auto; currently java
(gdb) bt
#0 0x400b3844 in java::lang::Thread::interrupted ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/lang/Thread.java:276
#1 0x400ebfae in java::io::FileDescriptor::write ()
at java/io/natFileDescriptor.cc:232
#2 0x4009b1c0 in java::io::FileOutputStream::write ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/io/FileOutputStream.jav
a:34
#3 0x40094043 in java::io::BufferedOutputStream::flush ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/io/BufferedOutputStream
.java:70
#4 0x400a0ddd in java::io::PrintStream::flush ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/io/PrintStream.java:90
#5 0x400a0efc in java::io::PrintStream::print ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/io/PrintStream.java:90
#6 0x400a19b5 in java::io::PrintStream::println ()
at
/home2/jcej/ThirdParty/libgcj-2.95.1/libjava/java/io/PrintStream.java:90
#7 0x804ad9e in Test.HelloWorld ()
#8 0x804ad14 in main ()
#9 0x401dfa12 in __libc_start_main ()
(gdb) The program is running. Exit anyway? (y or n) y
More information about the Java
mailing list