[CMake] CMake incorrectly passes linker flags to ar

Alan Burlison Alan.Burlison at oracle.com
Mon Jan 11 09:42:00 EST 2016


I've just moved from CMake 2.8.6 to 3.3.2 and creation of static 
libraries is now failing. I've localised the problem as far as the 
generated link.txt linker script. With 2.8 it begins with:

/usr/bin/ar cr target/usr/local/lib/libhadoop.a

with 3.3.2 it begins with:

/usr/bin/ar cq target/usr/local/lib/libhadoop.a -m64

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

However "-m64" is not a valid "ar" flag. I haven't been able to find 
exactly how the linker flags are transmogrified into ar flags but I did 
find the following in Modules/CMakeCXXInformation.cmake:

if(NOT DEFINED CMAKE_CXX_ARCHIVE_CREATE)
   set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> cq <TARGET> <LINK_FLAGS> 
<OBJECTS>")
endif()

But I'm struggling to understand when passing in linker flags to ar 
*ever* makes sense, at least on *nix platforms. And that code seems to 
be the same in 2.8.6 and 3.3.2 so it doesn't explain why the incorrect 
flags to ar have appeared in 3.3.2.

This looks like a bug to me...

-- 
Alan Burlison
--


More information about the CMake mailing list