[CMake] CMAKE_<LANG>_FLAGS added to link rule

Brad King brad.king at kitware.com
Tue Jul 13 08:57:12 EDT 2010


On 07/12/2010 04:16 PM, Michael Hertling wrote:
> In GCC's documentation, one can read:
> 
> "-shared
>     Produce a shared object which can then be linked with other objects
>     to form an executable. Not all systems support this option. For
>     predictable results, you must also specify the same set of options
>     that were used to generate code (-fpic, -fPIC, or model suboptions)
>     when you specify this option.[1]"
> 
> "[1] On some systems, `gcc -shared' needs to build supplementary stub
>      code for constructors to work. On multi-libbed systems, `gcc
>      -shared' must select the correct support libraries to link
>      against. Failing to supply the correct flags may lead to subtle
>      defects. Supplying them in cases where they are not necessary is
>      innocuous."
> 
> Apparently, there may be - at least with GCC and shared libraries - a
> need to specify flags on the link line if they have been specified on
> the compile line before. Though, I don't know an example of a damaged
> binary due to different sets of flags for compiling and linking.

Ah!  You just reminded me why CMake passes the compilation flags to the
compiler when using it to link.  Some compilers implement template
instantiation using a pre-linker.  It essentially runs the compiler on
a few translation units again to assign template instantiations to them.
Of course this needs the same compilation flags as were used the first
time to produce compatible object files (especially flags like -m64).

Thanks!
-Brad


More information about the CMake mailing list