0

I am building a shared library for the Debian GNU/Linux distribution and I am worried about the number of symbols from internal functions that it exports without any need. Since the library is built using autoconf/automake/libtool, the answer is easy: I can just add -export-symbols libfoo.sym to libfoo_la_LDFLAGS and specify only the symbols I want exported in that file.

But since this involves error-prone manual work, I figured that there has to be a better way. Is it possible to automate reading the (in this case) dozens of .h files that accompany the library and generate a first version of the libfoo.syms file.

Could I just use the C (or C++) compiler to do the busy work for me?

hillu
  • 9,423
  • 4
  • 26
  • 30
  • 1
    If you've used some sort of 'namespace' for the library API, you might consider using the `-export-symbols-regex REGEX` option. – Brett Hale Jan 23 '14 at 16:19
  • @BrettHale yeah, I had considered that, but to be sure, I still need to read all those header files. (I am not the author.) – hillu Jan 23 '14 at 16:21
  • 1
    The only other way to automate the process that I can think of is to use [ctags](http://ctags.sourceforge.net/). Chances are it is already installed on your system. – Brett Hale Jan 23 '14 at 16:38

2 Answers2

0

This is equivalent to extracting function prototypes and covered here: Extracting C / C++ function prototypes

Community
  • 1
  • 1
Carlos O'Donell
  • 594
  • 3
  • 10
0

But since this involves error-prone manual work, I figured that there has to be a better way. Is it possible to automate reading the (in this case) dozens of .h files that accompany the library and generate a first version of the libfoo.syms file.

It might be more useful to use nm on the object files instead of trying to parse header files. nm can be told to restrict the output to just exports.

Could I just use the C (or C++) compiler to do the busy work for me?

Certain compilers have tools to assist with this, like gcc's visibility support.

But the real problem is you must know what functions must be exported and which must not.

ldav1s
  • 15,885
  • 2
  • 53
  • 56