[ 
http://jira.codehaus.org/browse/MOJO-1650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=258352#action_258352
 ] 

Jean-Marie Dautelle edited comment on MOJO-1650 at 3/3/11 8:42 AM:
-------------------------------------------------------------------

{noformat} 
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -24,6 +24,7 @@
  * SOFTWARE.
  */
 
+import java.io.IOException;
 import org.codehaus.mojo.natives.NativeBuildException;
 import org.codehaus.mojo.natives.linker.AbstractLinker;
 import org.codehaus.mojo.natives.linker.LinkerConfiguration;
@@ -32,8 +33,10 @@
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.util.Iterator;
 import java.util.List;
+import org.codehaus.plexus.util.Os;
 
 /**
  * Generic C/CPP linker with "-o " as its output option 
@@ -76,15 +79,42 @@
             cl.createArg().setValue( linkerOutputOption + 
config.getOutputFile() );
         }
 
+        // On windows to avoid command lines too long we have to use a linker 
response file.
+        if ( ( objectFiles.size() > 32 ) && ( Os.isFamily( Os.FAMILY_WINDOWS ) 
|| Os.isFamily( Os.FAMILY_WIN9X ) ) )
+        {
+            try
+            {
+                File linkerFile = new File( 
config.getWorkingDirectory().getPath(), "objectsFile" );
+                FileWriter linkerFileWriter = new FileWriter( linkerFile, 
false /* Don't append */);
         for ( int i = 0; i < objectFiles.size(); ++i )
         {
-            File objFile = (File) objectFiles.get( i );
+                    File objFile = ( File ) objectFiles.get( i );
             
+                    // Shorten the command line.
+                    String objFilePath = FileUtil.truncatePath( 
objFile.getPath(), config.getWorkingDirectory().getPath() );
+                    linkerFileWriter.write(objFilePath + "\n");
+                }
+                linkerFileWriter.close();
+            }
+            catch ( IOException error )
+            {
+                throw new NativeBuildException( "Error creating linker 
response file", error);
+            }
+            cl.createArg().setValue("@objectsFile");
+        }
+        else
+        { // Normal behavior.
+
+            for ( int i = 0; i < objectFiles.size(); ++i )
+            {
+                File objFile = ( File ) objectFiles.get( i );
+
             //we need to shorten the command line since windows has limited 
command line length
             String objFilePath = FileUtil.truncatePath( objFile.getPath(), 
config.getWorkingDirectory().getPath() );
             
             cl.createArg().setValue( objFilePath );
         }
+        }
 
         if ( config.getMiddleOptions() != null )
         {
{noformat} 

      was (Author: dautelle):
    # This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -24,6 +24,7 @@
  * SOFTWARE.
  */
 
+import java.io.IOException;
 import org.codehaus.mojo.natives.NativeBuildException;
 import org.codehaus.mojo.natives.linker.AbstractLinker;
 import org.codehaus.mojo.natives.linker.LinkerConfiguration;
@@ -32,8 +33,10 @@
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.File;
+import java.io.FileWriter;
 import java.util.Iterator;
 import java.util.List;
+import org.codehaus.plexus.util.Os;
 
 /**
  * Generic C/CPP linker with "-o " as its output option 
@@ -76,15 +79,42 @@
             cl.createArg().setValue( linkerOutputOption + 
config.getOutputFile() );
         }
 
+        // On windows to avoid command lines too long we have to use a linker 
response file.
+        if ( ( objectFiles.size() > 32 ) && ( Os.isFamily( Os.FAMILY_WINDOWS ) 
|| Os.isFamily( Os.FAMILY_WIN9X ) ) )
+        {
+            try
+            {
+                File linkerFile = new File( 
config.getWorkingDirectory().getPath(), "objectsFile" );
+                FileWriter linkerFileWriter = new FileWriter( linkerFile, 
false /* Don't append */);
         for ( int i = 0; i < objectFiles.size(); ++i )
         {
-            File objFile = (File) objectFiles.get( i );
+                    File objFile = ( File ) objectFiles.get( i );
             
+                    // Shorten the command line.
+                    String objFilePath = FileUtil.truncatePath( 
objFile.getPath(), config.getWorkingDirectory().getPath() );
+                    linkerFileWriter.write(objFilePath + "\n");
+                }
+                linkerFileWriter.close();
+            }
+            catch ( IOException error )
+            {
+                throw new NativeBuildException( "Error creating linker 
response file", error);
+            }
+            cl.createArg().setValue("@objectsFile");
+        }
+        else
+        { // Normal behavior.
+
+            for ( int i = 0; i < objectFiles.size(); ++i )
+            {
+                File objFile = ( File ) objectFiles.get( i );
+
             //we need to shorten the command line since windows has limited 
command line length
             String objFilePath = FileUtil.truncatePath( objFile.getPath(), 
config.getWorkingDirectory().getPath() );
             
             cl.createArg().setValue( objFilePath );
         }
+        }
 
         if ( config.getMiddleOptions() != null )
         {

  
> Link command too long on Windows
> --------------------------------
>
>                 Key: MOJO-1650
>                 URL: http://jira.codehaus.org/browse/MOJO-1650
>             Project: Mojo
>          Issue Type: Improvement
>          Components: native
>            Reporter: Jean-Marie Dautelle
>            Priority: Blocker
>         Attachments: CLinker.java
>
>
> When there are too many object files, the command line generated by the 
> linker is too long (> 8192) on Windows.
> An easy fix is to use a linker response file (@objectFiles) instead of having 
> all objects as argument of the command line (replacing n argument with one).
> Attached is org.codehaus.mojo.natives.c.CLinker modified to use a linker 
> response file on Windows if the number of objects to link is greater than 32.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to