This is the mail archive of the java@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]

Re: Segfault with trivial SWT snippet


Carl Worth writes:
 > On Wed, 14 Nov 2007 14:50:40 +0000, Andrew Haley wrote:
 > > Carl Worth writes:
 > >  > Oh, but by the way, I couldn't get things to link when passing the
 > >  > -findirect-dispatch flag. I always got errors like:
 > >  >
 > >  > 	gcj -I `pkg-config --variable=CLASSPATH swt-gtk`
 > >  > 	-findirect-dispatch -fpic -fjni -c -o Snippet1.o Snippet1.java
 > >  > 	gcj -lswt --main=Snippet1 -o Snippet1 Snippet1.o
 > >  > 	/tmp/cceivJSw.o: In function `main':
 > >  > 	ccUlWBRV.i:(.text+0x2b): undefined reference to `Snippet1::class$'
 > >
 > > You seem to have forgotten about -findirect-dispatch -fpic !
 > 
 > OK. That's fairly embarrassing.
 > 
 > I had really meant to stick to compile-and-link with one command to
 > avoid issues like this. Anyway, it does work if I do it correctly. For
 > example:
 > 
 > 	gcj -I `pkg-config --variable=CLASSPATH swt-gtk` \
 > 	-findirect-dispatch -fpic -fjni \
 > 	-lswt --main=Snippet1 -o Snippet1 Snippet1.java
 > 
 > And it also works without those flags:
 > 
 > 	gcj -I `pkg-config --variable=CLASSPATH swt-gtk` -lswt \
 > 	--main=Snippet1 -o Snippet1 Snippet1.java
 > 
 > I'm curious now if there's a significant difference one way or the
 > other? Is something different happening or is the compiler figuring
 > things out and acting the same in both cases?

You are doing very different things in the two cases.  The default way
of linking binds everything at compile time.  -findirect-dispatch
-fpic means that all linking is postponed to runtime.  This has the
great advantage that if the libraries are upgraded your program will
continue to work.  This does mean that programs run more slowly, but
it is far more robust.

I'm not sure exactly why you get the segfault if a library isn't
linked, though.  It's a bit of a mystery.

Andrew.


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