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: gcj with swt or motif


Hi David,

You've probably noticed that the gcj mailing list archives are used by large
numbers of developers as a searchable (e.g. through Google) repository of
information and fixes. You may send queries to me directly, but I feel that
you should put the mailing list at least in Cc.

Concerning the statically compiled swt*.a files, you have to create them by
compiling from source. They are not hard to create. There is the java part
and the jni part.

For the java part, you should create a corresponding *.o tree (corresponding
to the sources). With Ant, you could use something similar to the following
expression:

<target name="obj-compile" depends="init">
        <apply failonerror='true' executable='${gcj}' dest='${obj}'>
            <arg value='-fCLASSPATH=${jarswtlin32}'/>
            <arg value='-c'/>
            <arg value='-fjni'/>
            <srcfile/>
            <arg value='-o'/>
            <targetfile/>
            <fileset dir='src/'>
 </fileset>
            <mapper type='glob' from='*.java' to='*.o'/>
        </apply>
</target>

You can also use 'make', if you're into that; or shell/perl scripts.

Next, you can create the .a archive. With Ant, you could use something
similar to:

        <apply failonerror="true" executable="ar" parallel="true">
            <fileset dir="${obj}/org/eclipse/swt" includes="**/*.o"/>
            <arg line="-crs ${arcswtlin32}"/>
       </apply>

You may have to split this command, because it could be to large for the
command line buffer.

For the jni part, you should recover the *.o files created by the makefile
supplied. No need to compile the C sources in any other way:

        <apply failonerror="true" executable="ar" parallel="true">
            <fileset dir="src" includes="structs.o"/>
            <fileset dir="src" includes="swt.o"/>
            <fileset dir="src" includes="callback.o"/>
            <arg line="-crs ${arcswtjnilin32}"/>
       </apply>

Now you should have the two *.a files needed: ${arcswtlin32} and
${arcswtjnilin32}. My script also creates the windows versions
(arcswt*win32).

The application that needs swt support can now link these *.a files:

gcj -Xlinker --start-group ${apparchives}
${arcsswtlin32} -Xlinker --end-group -o ${outexe} --main=${mainclass-client}
${swtdeps}

The variables are:

${apparchives}
: the .a file(s) created from your application sources. You can create the
in a similar way as the swt java part above.
${arcsswtlin32}
= ${arcswtlin32} -Wl,--whole-archive
${arcswtjnilin32} -Wl,--no-whole-archive
: Note that the --whole-archive option forces the linker to include the
archive even though it is not referenced explicitly (only dynamically
through ltdl).
: Without --whole-archive, you will find that the ltdl lookups for jni
symbols will fail invariably.
${swtdeps}
= -export-dynamic -L/usr/X11R6/lib -lgtk-x11-2.0 -lgdk-x11-2.0  -latk-1.0 -l
gdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0  \
                -lpango-1.0 -lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0 -lgt
hread-2.0 -lpthread
: You may have to add other locations (-L...) if your LD_LIBRARY_PATH does
not contain all gtk and other libraries mentioned in this line depending on
how all these things were compiled and linked in your installation.
: you need -export-dynamic for the executable to expose the jni symbols; so
that ltdl can find them.

This should be the gist of how to link statically on linux all the way down
to gtk. I've tested it on Ret Hat 8.0 and someone else on Red Hat 9.0. There
is no apparent reason why it should not work for Motif; mutatis mutandis, of
course.

To link gtk itself statically I haven't tried by myself. I just know that
adding "-static" is not sufficient.

Hope this helps.


-----Original Message-----
From: David Young [mailto:dvd at OCF dot Berkeley dot EDU]
Sent: Tuesday 15 April 2003 02:00
To: Erik Poupaert
Subject: Re: gcj swt (motif) -- ADDENDUM


Hi Erik,

Both swt-gtk and swt-motif worked with gcj!  As you noted, evidently the
problem lay in my original linker syntax.  As corrections, I used
"-L/librarysearchpath" to add a search directory for the libraries, while
"-lswt-gtk-XXXX", without the "lib" at the front or the ".so" at the end,
identified the library itself.  With swt-motif, your patches applied
virtually the same as with swt-gtk.

So far I have tried the separately compiled libswt-gtk*.so's, and now I am
looking into the statically compiled libswt-gtk*.a's that you mentioned.
May I ask where you got these .a files?  Should I recompile the libraries?
I'm using the swt-2.1-linux-motif and -gtk binary/source downloads (eg
http://download2.eclipse.org/downloads/drops/R-2.1-200303272130/download.php
?dropFile=swt-2.1-linux-motif.zip).

Attached is my test program build script.  Thanks again for your help with
swt/gcj.


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