[CMake] Use of -fPIC when linking executables

Brad King brad.king at kitware.com
Tue Mar 14 09:05:07 EST 2006


Lars Nordlund wrote:
> This simple CMakeLists.txt will (on NetBSD at least) cause the binary
> 'bar' to be linked with -fPIC. Is this really necessary? I know that it
> must be used when producing the shared object 'foo', but I did not know
> it was needed for the executable also? I have checked the flags passed
> from gcc to the linker during the linking of the executable but can not
> see that -fPIC makes any difference.

If any of the libraries to which the executable links are shared then 
-fPIC must be used in the link.  It isn't absolutely necessary on all 
platforms but the same code generates the rules for other platforms too. 
  Is it breaking something for you?

-Brad


More information about the CMake mailing list