[CMake] Compiling static and shared library only once (wiki seems to have an error)

Hendrik Sattler post at hendrik-sattler.de
Sat Apr 18 03:16:45 EDT 2009


Am Samstag 18 April 2009 03:43:42 schrieb Philip Lowman:
> On Fri, Apr 17, 2009 at 2:23 PM, Hendrik Sattler <post at hendrik-
sattler.de>wrote:
> > Am Freitag 17 April 2009 20:13:40 schrieb Shaun Cummins:
> > > Thanks, that solves one problem. I still haven't found a way to create
> > > both shared and static libraries by only compiling the source code
> > > once (on Linux). I can generate both types of libraries in one make
> > > command but each source file is compiled twice.
> > >
> > > Does anyone know how to do this?
> >
> > You cannot as one has is compile as PIC and one as non-PIC.
>
> I've done this before in my pre-cmake days on Linux and didn't run into any
> problems.  Obviously Windows is out in terms of reusing static object files
> as shared libraries.  What about MacOSX and older Unix systems?  Can you
> reuse code compiled with -fPIC in static libraries without any problems?

PIC code by definition is slower than non-PIC code. As PIC is not needed for 
linking an application with a static library, it is usually not used. You can 
have PIC compiled static libraries when you want to add those to a shared 
library. X did have PIC compiled shared libraries named with a '_pic.a' suffix.

Even libtool compiles twice when creating shared and static libraries.

HS



More information about the CMake mailing list