Using Autotools for shared library builds (was Re: [ROOT] Problem w/ Shared Library)

From: Christian Holm Christensen (
Date: Fri Aug 30 2002 - 12:16:05 MEST


On Thu, 29 Aug 2002 16:51:48 -0400
Brett Viren <> wrote
concerning "Re: [ROOT] Problem w/ Shared Library":
> Hi,
> It looks like you are missing the "-shared" flag when you create
> your library.  

Another way to go about all this in a portable (on Un*x at least), is
to use Autotools.  I wrote  a detailed example ones [1].  But see also
the root-config(1) man(1) page.  In essence, you create should have 

  myproject -+-  (or for autoconf < 2.50)
	     +- MyClass.hh 
	     +- MyLinkDef.hh 

[Note that the last part of the file names are not really important.
If you feel more comfortable with `.cxx' and `.h', use that.  Some
compiles may not recognise files ending in `.cc' as C++ source files,
and will bark at you.] 

`' contains: 

  AC_INIT(My Project, 0.1, my@email, myproject)
  AC_COPYRIGHT(GNU General Public License)

Alternatively `':

  AM_INIT_AUTOMAKE(myproject, 0.1)

and `'

  AUTOMAKE_OPTIONS          = gnu
  AM_CPPFLAGS               = -I@ROOTINCDIR@
  pkglib_LTLIBRARIES        = 
  pkginclude_HEADERS        = MyProject.hh 
  noinst_HEADERS            = MyLinkDef.hh 
  libMyProject_la_SOURCES   = MyDictionary.cxx 
  libMyProject_la_LDFLAGS   = -version 0:0:0 %Dictionary.h:$(pkginclude_HEADERS) %LinkDef.hh
  	     @ROOTCINT@ -f $*.cc -c $(AM_CPPLFAGS) $(INCLUDES) $^ 

Then do: 

  prompt> aclocal      # create aclocal.m4 - only needed once 
  prompt> automake -a  # create - only needed once 
  prompt> autoconf     # create configure - only needed once 

Now your source tree is ready to be configured and built. Do 

  prompt> ./configure 
  prompt> make 
  prompt> make install 

This will install your stuff like: 

  <prefix>/lib/myproject/ ->
  <prefix>/lib/myproject/ ->
where <prefix> per default is `/usr/local'.  Choose your prefix by
passing the `--prefix=<prefix>' option to `configure'. 

This will work on most Un*x systems, as well as MacOSX (with Fink
[2]), and most like also Windoze (with Cygwin [3]) with a reasonably
new set of autotools. See also the "Goat book" [4] from O'Reilly 
avaliable online [5] too. This will also work regardless of wether you
have a ROOTSYS driven installation of ROOT, or if you have a
fixed-directory install of ROOT. 

One caveat:  If the file `root.m4' isn't in the path search by `aclocal'
(usually /usr/share/aclocal), then you need to copy the contents of
that file to acinclude.m4 in the `myproject' directory.  `root.m4' can
be found in the ROOT source tree in `build/misc/root.m4'.  If you used
a fixed-directory install with `--prefix=/usr' or installed ROOT as a
Debian GNU/Linux or Red Hat package then `root.m4' is already in
place, and you needn't do anything.  

If you intend to use your library only as a loadable module, modify
the to read 

  AUTOMAKE_OPTIONS          = gnu
  AM_CPPFLAGS               = -I@ROOTINCDIR@
  pkglib_LTLIBRARIES        = 
  pkginclude_HEADERS        = MyProject.hh 
  noinst_HEADERS            = MyLinkDef.hh 
  MyProject_la_SOURCES      = MyDictionary.cxx 
  MyProject_la_LDFLAGS      = -module -avoid-version %Dictionary.h:$(pkginclude_HEADERS) %LinkDef.hh
  	     @ROOTCINT@ -f $*.cc -c $(AM_CPPLFAGS) $(INCLUDES) $^ 


 ____ |  Christian Holm Christensen 
  |_| |	 -------------------------------------------------------------
    | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|	          Denmark                    Office: (+45) 353  25 305
 ____|	 Email:               Web:
 | |


This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:51:06 MET