MantisBT - CMake
View Issue Details
0013897CMakeCMakepublic2013-02-07 16:212016-06-10 14:31
Eric Gross 
Kitware Robot 
normalminoralways
closedmoved 
Windows cross compiling to LinuxWindows 7 x64
CMake 2.8.10.2 
 
0013897: Cross-compiling from Windows with a Linux-GCC toolchain exceeds max command line length during linking
When compiling using GCC on Windows as a non-cross-compile, CMake has code in the platform files for using a response file to pass the objects to GCC's linker. When cross-compiling to a Linux toolchain, this workaround is not used. I was hitting this issue at around the 200-300 file count.

It seems that GCC supports the usage of response files across all OSes. Additionally, it seems that there are some cases that on certain Linux configurations (compiling natively) that they can run into the same issue as Windows. I believe CMake should use response files under the situation I am seeing (cross-compiling on Windows) and perhaps more universally.

I cross-compiled the GenICam GenAPI reference implementation from Windows to an ARM/Linux target. GenApi's source includes components Xerces and Xalan, both which have hundreds of files and hit this error. The error shown is an unterminated string in sh.exe because the line is truncated.

To work around this I added the following into the macro section of Linux-GNU.cmake (copied from the Windows version of that file):

    set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS 1)
    set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 1)


  # We prefer "@" for response files but it is not supported by gcc 3.
  execute_process(COMMAND ${CMAKE_${lang}_COMPILER} --version OUTPUT_VARIABLE _ver ERROR_VARIABLE _ver)
  if("${_ver}" MATCHES "\\(GCC\\) 3\\.")
    if("${lang}" STREQUAL "Fortran")
      # The GNU Fortran compiler reports an error:
      # no input files; unwilling to write output files
      # when the response file is passed with "-Wl,@".
      set(CMAKE_Fortran_USE_RESPONSE_FILE_FOR_OBJECTS 0)
    else()
      # Use "-Wl,@" to pass the response file to the linker.
      set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "-Wl,@")
    endif()
    # The GNU 3.x compilers do not support response files (only linkers).
    set(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_INCLUDES 0)
  elseif(CMAKE_${lang}_USE_RESPONSE_FILE_FOR_OBJECTS)
    # Use "@" to pass the response file to the front-end.
    set(CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG "@")
  endif()
No tags attached.
Issue History
2013-02-07 16:21Eric GrossNew Issue
2013-02-07 16:22Eric GrossNote Added: 0032217
2013-02-08 09:43Brad KingNote Added: 0032223
2013-02-08 09:52Eric GrossNote Added: 0032224
2013-02-08 11:12Eric GrossNote Added: 0032227
2013-02-08 13:56Brad KingNote Added: 0032232
2016-06-10 14:28Kitware RobotNote Added: 0042219
2016-06-10 14:28Kitware RobotStatusnew => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0032217)
Eric Gross   
2013-02-07 16:22   
GenApi reference implementation (builds with CMake) is here: http://www.emva.org/cms/index.php?idcatart=76&client=1&lang=1 [^]
(0032223)
Brad King   
2013-02-08 09:43   
Rather than duplicating it between Platform/Linux-GNU.cmake and Platform/Windows-GNU.cmake, try putting it in Compiler/GNU.cmake in a relevant location.

I've never seen response files needed other than on Windows hosts. Perhaps the new block can be conditioned in if(WIN32).
(0032224)
Eric Gross   
2013-02-08 09:52   
On some Unix environments, there are hard limits in argument length or limits due to stack space. Google seems to say that Linux <=2.6 had such limits. I think these restrictions are typically less of an issue than Windows, but I suspect you will still likely run into them on some platforms. If GCC supports response files across the board and CMake has common internally for using it, it seems like this functionality should be exposed in a manner that can be easily enabled when needed without having to modify your locally installed platform files. To me it might make sense to just always use them...
(0032227)
Eric Gross   
2013-02-08 11:12   
Brad, how does CMake differentiate between the build platform and the target platform to be cross-compiled to? Wouldn't "If(WIN32)" not be true if I am cross-compiling to Linux?
(0032232)
Brad King   
2013-02-08 13:56   
Re 0013897:0032227: Right. Use the CMAKE_HOST_SYSTEM_NAME variable:

 http://www.cmake.org/cmake/help/v2.8.10/cmake.html#variable:CMAKE_HOST_SYSTEM_NAME [^]

if it is set and otherwise CMAKE_SYSTEM_NAME.
(0042219)
Kitware Robot   
2016-06-10 14:28   
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.