View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015650CMakeCMakepublic2015-07-14 07:072016-06-10 14:31
ReporterAbigail 
Assigned ToKitware Robot 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionmoved 
PlatformApple MacOSMac OS XOS Version10.10.3
Product VersionCMake 3.2.3 
Target VersionFixed in Version 
Summary0015650: Linking large files on OS X can result in linker failing with "command line too long" error
DescriptionWhen 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.
Steps To ReproduceIn 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
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0039136)
Abigail (reporter)
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 (manager)
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 (administrator)
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.

 Issue History
Date Modified Username Field Change
2015-07-14 07:07 Abigail New Issue
2015-07-14 09:19 Abigail Note Added: 0039136
2015-07-14 09:38 Brad King Note Added: 0039137
2016-06-10 14:29 Kitware Robot Note Added: 0042808
2016-06-10 14:29 Kitware Robot Status new => resolved
2016-06-10 14:29 Kitware Robot Resolution open => moved
2016-06-10 14:29 Kitware Robot Assigned To => Kitware Robot
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team