[oclug] automake [was: static - > shared libs ]
Bart Trojanowski
bart at nexus.carleton.ca
Tue Jan 30 21:35:36 EST 2001
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
OK, shared libraries:
say you have foo.c and want to make a foo.so, here is what you need to do:
here is your makefile:
foo.so: foo.o
ld -m elf_i386 -r -o $@ $<
foo.o: foo.c
gcc -c -pipe -o $@ $<
then you run `make` and you have a foo.so. This is not perfect but should
get you started. Most of the time you want to version libraries. This is
done through extra tags to ld which I don't remember right now... I have
been using libtool to hide all that from me.
OK, a quick little blurb about automake for libraries; this is very very
much more involved for the above example. But believe me for large
projects it saves you lot of hassle and you end up with an environment
that can be compiled on multiple platforms (even Win32).
First of all you must understand something about how autoconf/automake
works:
Say you start off with a simple project, you will probably have
Makefile.am
configure.in
foo.c
(and some other automagically generated files)
Then you run the following commands to generate your base environment:
aclocal
autoheader
automake --add-missing --copy
autoconf
These are scripts that will generate other files that aid in compiling;
you will see
Makefile.am config.guess configure.in ltmain.sh
Makefile.in config.h.in foo.c missing
aclocal.m4 config.sub install-sh mkinstalldirs
bootstrap configure ltconfig stamp-h.in
... pretty heary eh? well, consider that most of these are generated for
you so there is not that much to do. Most people put the 4 commands
listed above into an script so that they don't have to run that.
I have attached the foo.c, Makefile.am, and configure.in so that you can
try it yourself.
Now how do I generate the file? You run:
$ ./configure --prefix `pwd`/target
$ make
The --prefix is used so that you can install in a directory other than
/usr/local/lib when you run `make install`.
A lot of files get generated in the last 4 command lines; What is
important to note some important ones:
program transform
------------------------------------------------
automake Makefile.am -> Makefile.in
autoconf configure.in -> configure
configure Makefile.in -> Makefile
Why all this? to make it portable. Imagine compiling on Solaris... well
you can. All the above generated files will be different, but the library
will compile even though the process is completely different using the
Solaris compiler. OK, maybe not completely different, but different
enough that you don't want to maintain a Makefile-linux and
Makefile-solaris. With autotools you get it for free.
Getting back to the game. The file that is generated by make is
'libfoo.la'; a quick inspection with less and you can see that this is
not a library. libtool generates a text file that describes what the
library looks like to make linking against it in a development environment
easier. The actual file is located in .libs directory. When you run make
install you will get the real .so file and the appropriate sym links for
versions.
$ mkdir target
$ make install
$ tree target
target
`-- lib
|-- libfoo.a
|-- libfoo.la
|-- libfoo.so -> libfoo.so.0.0.0
|-- libfoo.so.0 -> libfoo.so.0.0.0
`-- libfoo.so.0.0.0
And there you have it.
Questions?
Bart.
On Tue, 30 Jan 2001, Bart Trojanowski wrote:
>
> Actually it is quite easy. And even more easy if you use libtool. If you
> are running a recent distribution of any Linux and you have installed
> standard development tools you will have automake, autoconf, and libtool
> installed.
>
> Hmm I have been thinking about something that I could talk about at a
> meeting. Would anyone be interested in a short development howto on
> automake, autoconf, libtool? I realize that not all OCLUGers are
> developers so it would bore some.
>
> Mike, I am work now, I will send you an example automake configuration for
> building libraries. libtool will build shared libraries (.so) files if it
> can and static if the system you have does not support shared - some old
> *NIX's.
>
> Bart.
>
>
> On Tue, 30 Jan 2001, Mike Thomas wrote:
>
> >
> >
> > Has anyone converted static to shared libs on Linux? I have searched
> > everywhere and read that it is possible, but have found no directives to
> > do so. Apologies if this is an obvious one, I'm not a C hacker<g>.
> >
> > TIA,
> >
> > Mike
> >
> > _______________________________________________
> > oclug mailing list
> > oclug at lists.oclug.on.ca
> > http://www.oclug.on.ca/mailman/listinfo/oclug
> >
>
>
- --
WebSig: http://www.jukie.net/~bart/sig/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.1 (GNU/Linux)
Comment: Made with pgp4pine
iD8DBQE6d3oA+O7P5UIqmQARAmu+AJ41qyriEi1iN2zTJZVBGaBqn9O/OQCghBKT
+fvSCxjATbByMp9U5MX1qLk=
=4G+S
-----END PGP SIGNATURE-----
-------------- next part --------------
AUTOMAKE_OPTIONS = foreign
lib_LTLIBRARIES = libfoo.la
libfoo_la_SOURCES = foo.c
libfoo_la_LDFLAGS = -dynamic
-------------- next part --------------
dnl Process this file with autoconf to produce a configure script.
AC_INIT(foo.c)
AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE(foo, 1.0)
dnl Checks for programs.
AC_PROG_CC
AM_PROG_LIBTOOL
dnl Checks for libraries.
dnl Checks for header files.
AC_HEADER_STDC
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)
-------------- next part --------------
int
foo(void)
{
return 1;
}
More information about the OCLUG
mailing list