Reputation: 812
I am the maintainer of twolame, a MPEG Audio Layer 2 encoding library. It is built using autoconf/automake/libtool.
As part of the build/test process I would like to get a list of visible/exported symbols and compare it to a version controlled file, to ensure that only the expected symbols are visible.
On Mac OS, I can use nm -g libtwolame/.libs/libtwolame.dylib
to successfully get a list of the symbols. I intend to then write a script to extract the symbols from the nm
output and compare it to a file as part of the make check
target.
But am not sure how to calculate the path of the binary library in a script. Is there a way to ask libtool
, to take libtwolame/libtwolame.la
and return libtwolame/.libs/libtwolame.dylib
(or libtwolame/.libs/libtwolame.so
on Linux)?
Or anything that can be done with automake macros?
Upvotes: 2
Views: 430
Reputation: 37747
If you already have a version controlled file containing the list of exported symbols (say, libtwolame.sym
) you can just tell libtool to only export the symbols listed in that file.
It only takes three lines added to Makefile.am
:
EXTRA_DIST += libtwolame.sym
libtwolame_la_DEPENDENCIES += ${srcdir}/libtwolame.sym
libtwolame_la_LDFLAGS += -export-symbols ${srcdir}/libtwolame.sym
We have been using that system for libgphoto2 for a long time to control the list of symbols exported to the users of our library as well for the symbols exported by the dynamically loaded camera drivers.
Caveat: Quoting the libtool manual (emphasis mine):
-export-symbols symfile
Tells the linker to export only the symbols listed in symfile. The symbol file should end in .sym and must contain the name of one symbol per line. This option has no effect on some platforms. By default all symbols are exported.
Upvotes: 2