Linking errors with GCJ and SWT
James Lee
jlee23@umbc.edu
Wed Feb 16 15:57:00 GMT 2005
Hello,
I am trying to compile a simple "Hello, World!" written in Java with
SWT. The code is as follows:
import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;
public class HelloWorld {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Label label = new Label(shell, SWT.NONE);
label.setText("Hello, World!");
label.pack();
shell.pack();
shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
display.dispose();
}
}
Compiling it with javac and running it with Sun's java works just fine,
however my initial attraction to SWT was the fact that it could be
compiled natively using GCJ. I have had relatively good experiences with
GCJ in the past with both non-GUI and java-gnome programs. Unfortunately
it's just not working out for me this time. I have installed SWT using
Portage. The SWT jar is in my classpath so the program compiles with gcj
fine like:
jlee@thinkpad ~ $ gcj -c HelloWorld.java
jlee@thinkpad ~ $
That leaves me with HelloWorld.o Then I have to link it, but it just
won't work. I have specified the location of the SWT library using the
-l option, but I just get the same error:
jlee@thinkpad ~ $ gcj --main=HelloWorld -lswt-gtk-3106 HelloWorld.o
HelloWorld.o(.text+0x1e): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Display::class$'
HelloWorld.o(.text+0x2d): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Display::Display()'
HelloWorld.o(.text+0x41): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Shell::class$'
HelloWorld.o(.text+0x57): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Shell::Shell(org::eclipse::swt::widgets::Display*)'
HelloWorld.o(.text+0x6b): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Label::class$'
HelloWorld.o(.text+0x89): In function `HelloWorld::main(JArray<java::lang::String*>*)':
: undefined reference to `org::eclipse::swt::widgets::Label::Label(org::eclipse::swt::widgets::Composite*, int)'
collect2: ld returned 1 exit status
jlee@thinkpad ~ $
There are a few swt libraries in /usr/lib:
/usr/lib/libswt-atk-gtk-3106.so /usr/lib/libswt-mozilla-gtk-3106.so
/usr/lib/libswt-gnome-gtk-3106.so /usr/lib/libswt-pi-gtk-3106.so
/usr/lib/libswt-gtk-3106.so
I have tried every and all of them. I just don't understand. I'd be
happy to provide anymore information. Thanks for the help!
James Lee
jlee23@umbc.edu
More information about the Java
mailing list