MantisBT - CMake
View Issue Details
0015650CMakeCMakepublic2015-07-14 07:072016-06-10 14:31
Abigail 
Kitware Robot 
normalmajoralways
closedmoved 
Apple MacMac OS X10.10.3
CMake 3.2.3 
 
0015650: Linking large files on OS X can result in linker failing with "command line too long" error
When a project contains sufficiently many source files - the one I'm compiling has 1689 .cpp files - the linker will fail, with the message "Error running link command: Argument list too long".

When using response lists (via set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)), the issue still occurs. This is because the response file is specified as a linker flag with @ResponseFile.rsp syntax, which is expanded by the compiler driver rather than being passed through and then expanded internally by the linker.

OS X's linker, ld64, doesn't support the @ResponseFile.rsp syntax, so it's not possible to work around this with set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "-Wl,@"). However, it does support -filelist, but this requires the file to be newline-separated rather than space-separated.
In an empty directory:

for i in {0000..9999}; echo "void f$i() {}" >> $i.c
find . > files.txt
cat << EOF > CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(long_file_test)
file(STRINGS "files.txt" files)
add_executable(long_file_test ${files})
EOF
cmake . && cmake --build . -- -j 24

...This will compile everything correctly, and then at the end emit:

[100%] Linking C executable long_file_test
Error running link command: Argument list too long
make[2]: *** [long_file_test] Error 2
make[1]: *** [CMakeFiles/long_file_test.dir/all] Error 2
make: *** [all] Error 2
No tags attached.
Issue History
2015-07-14 07:07AbigailNew Issue
2015-07-14 09:19AbigailNote Added: 0039136
2015-07-14 09:38Brad KingNote Added: 0039137
2016-06-10 14:29Kitware RobotNote Added: 0042808
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0039136)
Abigail   
2015-07-14 09:19   
I've compiled a patched version with a fix/workaround - the needed changes are https://github.com/AbigailBuccaneer/CMake/commit/0c6ff4e4c3e95adbcee65f716d31a2fba69a7539 [^]

With this, I can then use:

if(APPLE)
    set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_OBJECTS 1)
    set(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "-Wl,-filelist,")
    set(CMAKE_CXX_OBJECT_RESPONSE_FILE_SEPARATOR "\n")
endif()

in my CMake file and successfully link the project.

However, these settings should presumably be set in a standard CMake module based on whether the linker is ld64 or not, and I've not yet investigated where to set them.
(0039137)
Brad King   
2015-07-14 09:38   
Re 0015650:0039136: Thanks! Indeed those should be set by the platform modules rather than project code. Look at "Modules/Platform/Darwin-{Clang,GNU,Intel}.cmake" for adding them.
(0042808)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.