skeeto / w64devkit

Portable C and C++ Development Kit for x64 (and x86) Windows
The Unlicense
2.99k stars 210 forks source link

Bad file descsriptor in building with `make` in w64devkit on Windows 11 #107

Open VIS-WA opened 8 months ago

VIS-WA commented 8 months ago

I was trying to compile llama.cpp on a Windows 11 laptop with the instructions provided here. However, while using make in w64devkit console for building in directories containing spaces in their names, the make command fails with the following error:

Z:/Lab Work/llama.cpp $ make
process_begin: CreateProcess(C:\Users\Asus, C:/Users/Asus pc/Downloads/w64devkit-fortran-1.21.0/w64devkit/bin/sh.exe -c "cc  -Wl,-v 2>&1", ...) failed.
Makefile:206: pipe: Bad file descriptor
process_begin: CreateProcess(C:\Users\Asus, C:/Users/Asus pc/Downloads/w64devkit-fortran-1.21.0/w64devkit/bin/sh.exe -c "{ cc -dumpfullversion 2>/dev/null || cc -dumpversion; } | awk -F. '{ printf(\"%02d%02d%02d\", $1, $2, $3) }'", ...) failed.
scripts/get-flags.mk:3: pipe: Bad file descriptor
expr: syntax error
expr: syntax error
I llama.cpp build info:
I UNAME_S:   Windows_NT
I UNAME_P:   unknown
I UNAME_M:   x86_64
I CFLAGS:    -I. -Icommon -D_XOPEN_SOURCE=600 -DNDEBUG -D_WIN32_WINNT=0x602  -std=c11   -fPIC -O3 -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wshadow -Wstrict-prototypes -Wpointer-arith -Wmissing-prototypes -Werror=implicit-int -Werror=implicit-function-declaration -march=native -mtune=native -Xassembler -muse-unaligned-vector-move -Wdouble-promotion
I CXXFLAGS:  -I. -Icommon -D_XOPEN_SOURCE=600 -DNDEBUG -D_WIN32_WINNT=0x602  -std=c++11 -fPIC -O3 -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wmissing-declarations -Wmissing-noreturn -Xassembler -muse-unaligned-vector-move  -march=native -mtune=native -Wno-array-bounds
I NVCCFLAGS:
I LDFLAGS:
process_begin: CreateProcess(C:\Users\Asus, C:/Users/Asus pc/Downloads/w64devkit-fortran-1.21.0/w64devkit/bin/sh.exe -c "cc --version | head -n 1", ...) failed.
Makefile:530: pipe: No error
I CC:
process_begin: CreateProcess(C:\Users\Asus, C:/Users/Asus pc/Downloads/w64devkit-fortran-1.21.0/w64devkit/bin/sh.exe -c "g++ --version | head -n 1", ...) failed.
Makefile:531: pipe: No error
I CXX:

g++ -I. -Icommon -D_XOPEN_SOURCE=600 -DNDEBUG -D_WIN32_WINNT=0x602  -std=c++11 -fPIC -O3 -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function -Wmissing-declarations -Wmissing-noreturn -Xassembler -muse-unaligned-vector-move  -march=native -mtune=native -Wno-array-bounds examples/main/main.cpp ggml.o llama.o common.o sampling.o grammar-parser.o build-info.o console.o ggml-alloc.o ggml-backend.o ggml-quants.o -o main
make: *** [Makefile:584: main] Error 3

In the above, the folders where w64devkit and the llama.cpp are located are different, and both the directory locations have spaces (i.e Z:/Lab Work/llama.cpp and C:/Users/Asus pc/Downloads). I was able to build succesfully by placing the files in different folders named without spaces; however, I feel the need to support spaces in directory names is essential for a more flexible workflow.

I am raising this as an issue on both the repos (llama.cpp and wdevkit64) to both notify other users and the repo maintainers. Apologies for any typos.

Thanks

grable0 commented 8 months ago

This is actually a known CreateProcess limitation, paths with spaces needs to be quoted.

skeeto commented 8 months ago

I see it's hung up on a "$(shell ...)" in the Makefile. This should mostly work even if the tools or your working directory contains spaces. If I put both w64devkit and llama.cpp under paths with spaces, including different drives like you showed, it works for me, and I'm unable to reproduce the issue.

It's curious that the first argument to CreateProcess is populated. Make normally leaves it null when starting sh.exe. That suggests it's picking up something from your environment ($SHELL, etc.), or gets confused when searching $PATH. However, nothing I try reproduces the issue. There must be something in your environment triggering path-with-spaces bugs in GNU Make.

As a kind of "strace" I ran make under gdb with dprintfs in kernel32.dll (note: requires first starting once in order to load the DLL symbols):

(gdb) set new-console (gdb) dprintf KERNEL32!CreateProcessA,"1=%s\n",$rcx (gdb) dprintf KERNEL32!CreateProcessA,"2=%s\n",$rdx (gdb) dprintf KERNEL32!SearchPathA,"fname=%s\n",$rdx

In my own experiments, and shown in your output, the command line string is wrong, which is a Make bug. The executable path isn't quoted, making it ambiguous, invoking CreateProcess magic following a documented process that usually fixes it.

The SearchPathA argument also reveals Make is confused about $PATH and searches for the wrong file names — another Make bug. I thought maybe if you had something at "C:/Users/Asus" it would throw off that search, but when I tried it myself I couldn't cause a build issue.

VIS-WA commented 8 months ago

Can you suggest a way to log things better for debugging and reproducing the issue? Also there's no path as C:/Users/Asus on my system (so probably space is considered as a delimiter).

NeoZhangJianyu commented 6 months ago

@VIS-WA Could you try 1.19.0 version. It's working well.