Skip to content

Commit 7669f24

Browse files
committed
Force forward slash for writing @..txt files for gcc
It seems that on windows the compiler is not able to handle files written in the format "C:\path\to\object.o" but it must be either "C:/path/to/object.o" or "C:\\path\\to\\object.o" I don't know if this is a quirk of gcc or it has something to do with golang doing some extra excaping on command.Exec that we must do also on @..txt files.
1 parent abef32d commit 7669f24

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: legacy/builder/phases/linker.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package phases
1717

1818
import (
19+
"path/filepath"
1920
"strings"
2021

2122
"github.com/arduino/arduino-cli/legacy/builder/builder_utils"
@@ -57,14 +58,17 @@ func (s *Linker) Run(ctx *types.Context) error {
5758
}
5859

5960
func link(ctx *types.Context, objectFiles paths.PathList, coreDotARelPath *paths.Path, coreArchiveFilePath *paths.Path, buildProperties *properties.Map) error {
60-
quotedObjectFiles := utils.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes)
61-
objectFileList := strings.Join(quotedObjectFiles, " ")
61+
objectFileList := strings.Join(utils.Map(objectFiles.AsStrings(), wrapWithDoubleQuotes), " ")
6262

6363
// If the number of object files is too big, write it down into a file and reference
6464
// it using the @ parameter "@path/to/object_files.txt".
6565
if len(objectFileList) > 500 {
6666
objectFilesTxt := ctx.BuildPath.Join("object_files.txt")
67-
objectFilesTxt.WriteFile([]byte(strings.Join(quotedObjectFiles, "\n") + "\n"))
67+
// The files should be written with forward slashes, otherwise on Windows
68+
// gcc seems to be not able to find the file... does golang do extra escaping
69+
// on the command line that we do not do?
70+
files := utils.Map(utils.Map(objectFiles.AsStrings(), filepath.ToSlash), wrapWithDoubleQuotes)
71+
objectFilesTxt.WriteFile([]byte(strings.Join(files, "\n") + "\n"))
6872
objectFileList = "@" + objectFilesTxt.String()
6973
}
7074

0 commit comments

Comments
 (0)