[CMake] linking OBJECT libraries : Argument list too long

Biddiscombe, John A. biddisco at cscs.ch
Wed May 25 04:35:37 EDT 2016


When building OpenBLAS on OSX, the link line generated contains around 350K of text, and the max supported arg length is
getconf ARG_MAX  - returns 262144.
This causes the link phase to abort with
Error running link command: Argument list too long

The reason for the problem is that many libraries of Type OBJECT are built and produce huge numbers of object files are then added to one very large list which is then passed to the linker.

I implemented a simple(ish) fix, that doesn't quite work - for each subdirectory that generates object files, I set the CMAKE_FILES_DIRECTORY and specify the binary directory where the build should go using a single character counter 0,1,2,3,4 which is much shorter than the target name and it reduces the final arg size down almost enough

set(COUNTER_ 0)
foreach (SUBDIR ${SUBDIRS})
  set(CMAKE_FILES_DIRECTORY "/${COUNTER_}")
  add_subdirectory(${SUBDIR} ${CMAKE_BINARY_DIR}/${COUNTER_})
.....
  MATH(EXPR COUNTER_ "${COUNTER_}+1")
endforeach ()

example : make driver_level2 target
[  0%] Building C object OpenBLAS/driver/level2/CMakeFiles/driver_level2.dir/CMakeFiles/ssbmv_U.c.o
becomes
[  0%] Building C object 1/CMakeFiles/driver_level2.dir/1/ssbmv_U.c.o

and the link line is correspondingly shorter as the driver_level2 has been replaced in 2 places. The problem is that there is still an extra "CMakeFiles/driver_level2.dir" in the path to the object file that I would like to shorten/remove.

How can I do that?

NB. I am aware that I can turn the OBJECT libraries into normal libraries and link them conventionally, but I'd like to make this path shortening method work.

Thanks

JB
--
John Biddiscombe,                        email:biddisco @.at.@ cscs.ch
http://www.cscs.ch/
CSCS, Swiss National Supercomputing Centre  | Tel:  +41 (91) 610.82.07
Via Trevano 131, 6900 Lugano, Switzerland   | Fax:  +41 (91) 610.82.82

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160525/68ca72ae/attachment.html>


More information about the CMake mailing list