[CMake] Adding -fPIC to static libraries

Prakash Punnoor prakash at punnoor.de
Wed Mar 1 11:29:52 EST 2006


Am Mittwoch März 1 2006 17:19 schrieb Filipe Sousa:
> Prakash Punnoor wrote:
> > Am Mittwoch März 1 2006 16:29 schrieb Filipe Sousa:
> >
> > Not really helpfull regarding CMake, but are you doing something
> > non-portable, like linking the static lib into an shared lib (or libtool
> > lib)? This
>
> You're right, I'm linking static libraries into a shared lib, but I get
> the error before linking into the executable. Maybe this is
> non-portable, but works with Linux and Windows. But now I have to
> compile my project to Linux AMD64 and I don't have time to fix things.
> I'm adding -fPIC till I find a better solution.

It seems to work for linux and Windows as -fpic is not mandatory for shared 
libs there (though most tools compile -fpic neverthelss), and if you need 
maximum performance you don't want pic code either as you lose the ebx 
register due to the compiler being stupid. (But for non-pic shared libs 
start-up time will be longer due to run-time relocations needing to be 
performed.) For x86_64 is it mandatory, so linking in non-pic code into a 
shared lib is not allowed, thus the error message. So your work-around is 
probably the best you can do, esp as x86_64 has enough registers there 
shouldn't be a noticeable performance drop in case you link your static lib 
directly into an executable.

(That's why libtool makes one's life so much easier as you don't have to think 
about such problems anymore...)

Cheers,
-- 
(°=                 =°)
//\ Prakash Punnoor /\\
V_/                 \_V
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/cmake/attachments/20060301/6f7baa7c/attachment.pgp


More information about the CMake mailing list