[CMake] make install/strip does not strip static libraries

Andreas Pakulat apaku at gmx.de
Tue Mar 27 10:23:49 EDT 2012


On 27.03.12 09:45:47, Kyle Leber wrote:
> On Fri, Mar 23, 2012 at 4:20 PM, Kyle Leber <kleber at fastemail.us> wrote:
> 
> > Hi,
> >
> > I'm using cmake 2.8 and having an issue when I issue a 'make
> > install/strip'.  My project includes two libraries: one static and one
> > shared. The shared library gets properly stripped, but the static one does
> > not.  Do I need to specify a special parameter to get the static library to
> > be stripped or am I doing something else wrong?
> >
> > Thanks for the help!
> >
> > OS: Ubuntu 10.10
> > Compiler: g++ 4.4.5
> >
> > Kyle
> >
> 
> OK, I've done a little more research.  It looks like cmake_install.cmake
> that is generated in my build directory has install lines handling the
> shared libraries and the static libraries.
> 
> After the shared library is installed, there's a section like this:
> 
> IF(EXISTS "${file}" AND
>        NOT IS_SYMLINK "${file}")
>       IF(CMAKE_INSTALL_DO_STRIP)
>         EXECUTE_PROCESS(COMMAND "/usr/bin/strip" "${file}")
>       ENDIF(CMAKE_INSTALL_DO_STRIP)
>     ENDIF()
> 
> That clearly strips the files after they are installed.  However, in the
> section that installs my static library there is no such check to handle
> stripping the library.  Is this a missing feature in CMake, or is there a
> reason this is not supported?  I can run /usr/bin/strip on my .a static
> library without issue so I think it's a reasonable thing to expect.

Did you actually try linking against such a stripped static library? A
simple call of strip libfoo.a will remove all symbols from that library,
making it totally useless since you cannot link against it anymore. For
a shared library things are different since its not just a bundle of
object files (like a static library is), but rather contains additional
information allowing strip to just strip the stuff that cannot be used
from outside (i.e. private functions/classes etc.). 

Looking at strip's commandline parameters it might be possible to
manually strip just the symbols you don't want in the static library,
but this cannot be done by cmake automatically. So you'll have to create
a custom post-install command to do this for you.

Andreas



More information about the CMake mailing list