[CMake] CMake incorrectly passes linker flags to ar

Brad King brad.king at kitware.com
Mon Jan 11 10:26:56 EST 2016


On 01/11/2016 09:42 AM, Alan Burlison wrote:
> The "-m64" flag is used to tell the compiler/linker to create 64-bit 
> executables and is set via the following CMake variables:
> 
> CMAKE_EXE_LINKER_FLAGS
> CMAKE_SHARED_LINKER_FLAGS
> CMAKE_STATIC_LINKER_FLAGS

What is adding -m64 to CMAKE_STATIC_LINKER_FLAGS?  That value is indeed
meant to be used to pass flags to "ar" because CMake (for historical
reasons) abuses the term "linker" to refer to the archiver used for a
static library.

>    set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> <OBJECTS>")
> 
> But I'm struggling to understand when passing in linker flags to ar 
> *ever* makes sense, at least on *nix platforms.

The name "LINK_FLAGS" is used as a placeholder there to share the
implementation with similar substitutions done in actual link line
generation.  See above about the naming.

The question here is what changed between 2.8.6 and 3.3.2 that causes
-m64 to start showing up in CMAKE_STATIC_LINKER_FLAGS.

-Brad



More information about the CMake mailing list