Building native shared libraries with Ant and gcjlib

Description

gcjlib is an Ant task for building native shared libraries suitable for use with gcj.

Here's an example of building the ObjectWeb ASM project into native code:

  <target name="gcjlib" depends="compile" 
          description="Create native libraries for use with gcj" >

    <taskdef name="gcjlib"
             classname="org.spindazzle.ant.taskdefs.GcjLib" />

    <gcjlib name="lib-org-objectweb-asm">
     <classpath location="${out.build}" />
     <fileset dir="${out.build}" />
    </gcjlib>

  </target>
Add this fragment to ASM's build.xml file and run "ant gcjlib". On Linux, this will create a shared library called lib-org-objectweb-asm.so. Once you install this library, the gcj runtime's system classloader will pick up native versions of these classes instead of interpreting any bytecode it might find. This class loading feature is described in more detail in the GCC Manual.

Gcj is capable of compiling jar files directly into shared libraries. However this is often too demanding on memory and CPU for large jar files. gcjlib breaks the build process down into multiple steps - compiling groups of class files into a smaller number of intermediate object files before linking them together to create the final shared library. This has the added benefit of working around command line length limits on the build system.

In addition to automatic shared library construction, gcjlib will detect and attempt to resolve all library dependencies at link time. For instance, if you compile code that uses foo.bar.Zip, gcjlib will work with gcj to locate a shared library containing a native version of foo.bar.Zip and add that library to the final link line. gcjlib currently warns if it can't resolve dependencies. This will result in a shared library whose missing dependencies will have to be resolved at runtime.

Status

gcjlib can build shared libraries on Linux for large projects, like JacORB. Here's a TO DO list. If you are willing to help with any of these tasks, please contact me (green at spindazzle.org).

Download

gcjlib was written by Anthony Green (green at spindazzle.org) and made available under the LGPL license. The tarball and zip distributions includes both source code and a prebuilt jar file.

To perform a simple test of gcjlib, run the following command once you extract the source:

$ ant gcjlib
This should eventually generate lib-org-spindazzle-ant-taskdefs.so.

http://www.spindazzle.org/gcjlib/gcjlib-0.7-1.src.rpm

http://www.spindazzle.org/gcjlib/gcjlib-0.7-1.noarch.rpm

http://www.spindazzle.org/gcjlib/gcjlib-0.7.tar.gz

http://www.spindazzle.org/gcjlib/gcjlib-0.7.zip