Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial: compile for Windows on Linux with MinGW (cross compile) #168

Closed
Topping1 opened this issue Nov 22, 2022 · 35 comments
Closed

Tutorial: compile for Windows on Linux with MinGW (cross compile) #168

Topping1 opened this issue Nov 22, 2022 · 35 comments
Labels
build Build related issues

Comments

@Topping1
Copy link
Contributor

Topping1 commented Nov 22, 2022

First, install MinGW
sudo apt install g -mingw-w64-x86-64-posix
sudo apt install gcc-mingw-w64-x86-64-posix

Then, clone the repository
git clone https://github.com/ggerganov/whisper.cpp

  • then, for compilation, we need to modify the pthread flag and static link libgcc and libstdc as follows:

x86_64-w64-mingw32-gcc-posix -I. -O3 -std=c11 -mfma -mf16c -mavx -mavx2 -c ggml.c -o ggml.o

x86_64-w64-mingw32-g -posix -I. -I./examples -O3 -std=c 11 -lwinpthread -c whisper.cpp -o whisper.o

x86_64-w64-mingw32-g -posix -I. -I./examples -O3 -std=c 11 -static-libgcc -static-libstdc -lwinpthread examples/main/main.cpp ggml.o whisper.o -o main

the compiled executable was tested on an Intel 4th gen CPU and it worked BUT accented characters do not show correctly (not a problem for english). A workaround (the problem might be with MinGW): before using main.exe on a command prompt window, execute the command chcp 65001 (UTF-8 encoding).

Tried to run it on a 3rd gen intel CPU but did not work.

@regstuff
Copy link

Tested successfully on an i5-8300H. Failed on an old Pentium G4400.
If this works well, I suppose it would be a good idea to setup a Github Workflow to auto-compile whenever this repo is updated.

@ggerganov ggerganov added the build Build related issues label Nov 22, 2022
@ggerganov
Copy link
Owner

@Topping1
Very nice!
Can you try cross-compiling using x86_64-w64-mingw32-gcc-posix -lwinpthread without using mingw-std-threads?

x86_64-w64-mingw32-gcc-posix -I. -O3 -std=c11 -mfma -mf16c -mavx -mavx2 -c ggml.c -o ggml.o

x86_64-w64-mingw32-g  -posix -I. -I./examples -O3 -std=c  11 -lwinpthread -c whisper.cpp -o whisper.o

x86_64-w64-mingw32-g  -posix -I. -I./examples -O3 -std=c  11 -static-libgcc -static-libstdc   -lwinpthread examples/main/main.cpp ggml.o whisper.o -o main

I want to avoid adding the extra source files.

@regstuff
Yes - having a Github action to build a Windows executable would be great.
I think there are a lot of people that want to try Whisper on Windows without going through the hassle of compiling it.

@Topping1
Copy link
Contributor Author

@Topping1 Very nice! Can you try cross-compiling using x86_64-w64-mingw32-gcc-posix -lwinpthread without using mingw-std-threads?

x86_64-w64-mingw32-gcc-posix -I. -O3 -std=c11 -mfma -mf16c -mavx -mavx2 -c ggml.c -o ggml.o

x86_64-w64-mingw32-g  -posix -I. -I./examples -O3 -std=c  11 -lwinpthread -c whisper.cpp -o whisper.o

x86_64-w64-mingw32-g  -posix -I. -I./examples -O3 -std=c  11 -static-libgcc -static-libstdc   -lwinpthread examples/main/main.cpp ggml.o whisper.o -o main

I want to avoid adding the extra source files.

@regstuff Yes - having a Github action to build a Windows executable would be great. I think there are a lot of people that want to try Whisper on Windows without going through the hassle of compiling it.

I will try and report back. By the way, when browsing https://github.com/ggerganov/whisper.cpp/actions I found the item
ggml : fix Windows build #225 https://github.com/ggerganov/whisper.cpp/actions/runs/3509700272, and at the end of the page you can find that the "Artifacts Produced during runtime" section contains two automatically compiled windows executables (win32 and win64). I have tried the 64bit version and works ok on windows 10. I guess you already implemented the github action a couple of days ago.

@ggerganov
Copy link
Owner

Ah yes - I didn't even realise that the job already produces the executable. Not sure how to reference the latest one though - I would like to put a link the README.

I think it would be still useful to be able to cross compile using mingw, so if you get the chance to try it - let us know.

@Topping1
Copy link
Contributor Author

Ah yes - I didn't even realise that the job already produces the executable. Not sure how to reference the latest one though - I would like to put a link the README.

I think it would be still useful to be able to cross compile using mingw, so if you get the chance to try it - let us know.

Apparently, Github doesn´t have yet a way to reference the latest artifact from a build action (see https://stackoverflow.com/questions/60789862/url-of-the-last-artifact-of-a-github-action-build). In that stackoverflow question, a free service is mentioned that can generate a permanent link, for example https://nightly.link/ggerganov/whisper.cpp/actions/runs/3509700272/whisper-bin-x64.zip. Not sure if this link will work with new action runs, there is some documentation on the page that explains it in more detail.

@Topping1
Copy link
Contributor Author

@ggerganov compiling with the POSIX version worked! In summary:

sudo apt install g -mingw-w64-x86-64-posix

sudo apt install gcc-mingw-w64-x86-64-posix

In ggml.c line 18
change #include <Windows.h>
to
#include <windows.h>
#include <errno.h>

x86_64-w64-mingw32-gcc-posix -I. -O3 -std=c11 -mfma -mf16c -mavx -mavx2 -c ggml.c -o ggml.o

x86_64-w64-mingw32-g -posix -I. -I./examples -O3 -std=c 11 -lwinpthread -c whisper.cpp -o whisper.o

x86_64-w64-mingw32-g -posix -I. -I./examples -O3 -std=c 11 -static-libgcc -static-libstdc -lwinpthread examples/main/main.cpp ggml.o whisper.o -o main

This version still does not show correctly accented characters. I have tested the automatic win64 build and also shows this problem.

@Topping1
Copy link
Contributor Author

@ggerganov I found a workaround (the problem might be with MinGW): before using main.exe on a command prompt window, execute the command chcp 65001 (UTF-8 encoding).

@ggerganov
Copy link
Owner

@Topping1 Thank you for the efforts. I just pushed the windows.h fix on master and referenced this issue from the README for building with MinGW. If you want, you can update your original comment at the top of the thread with the latest instruction, so it is more visible when someone looks for the build steps.

@R4ZZ3
Copy link

R4ZZ3 commented Nov 25, 2022

Hi,

Any more detailed instructions coming? I have been able to get this working on WSL2.
Now I tried with compiling with the instructions above using Ubunt22.04 in WSL2.
First I got error that libwinpthread-1.dll is missing. Downloaded it from here https://www.dll-files.com/download/1e0d62c34ff2e649ebc5c372065732ee/libwinpthread-1.dll.html?c=OVhZYVRGRklHdFNGQWQ2NTZ3ZGVPdz09 and put it in the project root.

Then I tried main.exe again but still running into error "application did not start correctly"

@Topping1
Copy link
Contributor Author

Hi,

Any more detailed instructions coming? I have been able to get this working on WSL2. Now I tried with compiling with the instructions above using Ubunt22.04 in WSL2. First I got error that libwinpthread-1.dll is missing. Downloaded it from here https://www.dll-files.com/download/1e0d62c34ff2e649ebc5c372065732ee/libwinpthread-1.dll.html?c=OVhZYVRGRklHdFNGQWQ2NTZ3ZGVPdz09 and put it in the project root.

Then I tried main.exe again but still running into error "application did not start correctly"

@R4ZZ3 I have tried your setup (WSL2 but with ubuntu 20.04) with the instructions of the first message of this thread and could compile the file with no errors about libwinpthread-1.dll missing. Not sure what else can be happening. Maybe try to compile in a fresh install of a linux VM?

@R4ZZ3
Copy link

R4ZZ3 commented Nov 27, 2022

@Topping1
sudo apt install g -mingw-w64-x86-64-posix
sudo apt install gcc-mingw-w64-x86-64-posix

For me these run into error with Ubuntu 20.04
image

@R4ZZ3
Copy link

R4ZZ3 commented Nov 27, 2022

But I did not yet test with fresh install. Trying that now

@R4ZZ3
Copy link

R4ZZ3 commented Nov 27, 2022

Ended up using Debian. Still got that same libwinpthread-1.dll is missing error but after putting that file in the same folder as the main.exe got it working.

Windows 11, BUILD 22000.1219, Processor 11th Gen Intel(R) Core(TM) i5-11600K @ 3.90GHz, 3912 Mhz, 6 Core(s), 12 Logical Processor(s)
"Debian GNU/Linux 11 (bullseye)" (cat /otc-release)
5.15.74.2-microsoft-standard-WSL2 (uname -r)

@ash-kamrip
Copy link

I did everything and even got a main.exe but I couldn't run it on windows 11 , it gave me this error , any ideas ? do i have to provide some arguements while running it from cmd ?
image

@indokid9999
Copy link

I had no luck until i removed "-mavx2" option on the gcc compile. It still needs the libwinpthreads-1.dll in same folder.
No luck on accented character even with chcp 65001. thanks anyway Topping1.
I am using windows 8 (not 8.1).
@R4ZZ3 I could not install g and gcc-mingw-w64-x86-64-posix like you, but i could install g and gcc-mingw-w64-x86-64. the gcc/g posix variants were installed.

@indokid9999
Copy link

For those of you using old processors, code that was released after v1.04 seemed to cause a crash.
Deletion of the "-mfma" build flag swas the cause . My i5 cpu was released in early 2013 , predating the first intel CPU (Haswell) to include FMA. Haswell was first announced in mid 2013.
So im guessing that earler cpus will work with whisper.cpp but a lot slower.

@thewh1teagle
Copy link
Contributor

thewh1teagle commented Jan 12, 2024

Simple way to build it on msys2 in Windows:

  1. Download msys2 from msys2.org

  2. open ucrt64.exe terminal

  3. Install presquites

    pacman -S --needed git $MINGW_PACKAGE_PREFIX-{cmake,ninja,toolchain}
  4. Clone and build

    git clone https://github.com/ggerganov/whisper.cpp
    cd whisper.cpp
    cmake -B build .
    cmake --build build -j16 --config Release
  5. Use it 🎉

    cd build/bin
    ./main.exe

With CLBlast

  1. Add CLBlast
pacman -S --needed $MINGW_PACKAGE_PREFIX-clblast
  1. Build
cmake -B build -DWHISPER_CLBLAST=ON
cmake --build build -j16 --config Release

With OpenBLAS

  1. Install openblas
pacman -S --needed $MINGW_PACKAGE_PREFIX-openblas
  1. Build
export C_INCLUDE_PATH=${OPENBLAS_PATH}/include/openblas
export OPENBLAS_PATH=$MINGW_PREFIX
cmake -B build -DWHISPER_OPENBLAS=ON
cmake --build build -j16 --config Release

WIP: With Cuda

  1. Setup cuda
NAME=cuda_12.3.2_546.12_windows
pacman -S --needed $MINGW_PACKAGE_PREFIX-{7zip,wget}
wget -nc -q --show-progress https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/$NAME.exe
7z x -y -o$NAME $NAME.exe
mkdir -p $MINGW_PREFIX/opt/
mv $NAME $MINGW_PREFIX/opt/
  1. Build
NAME=cuda_12.3.2_546.12_windows
OPENBLAS_PATH=$MINGW_PREFIX cmake -B build -DWHISPER_CUBLAS=ON
cmake --build build -j16 --config Release

@kaushal2012
Copy link

Simple way to build it on msys2 in Windows:

  1. Download msys2 from msys2.org
  2. open ucrt64.exe terminal
  3. Install presquites
    pacman -S --needed git $MINGW_PACKAGE_PREFIX-{cmake,ninja,toolchain}
    
  4. Clone and build
    git clone https://github.com/ggerganov/whisper.cpp
    cd whisper.cpp
    cmake -B build .
    cmake --build build -j16 --config Release
    
  5. Use it 🎉
    cd build/bin
    ./main.exe
    

With CLBlast

  1. Add CLBlast
pacman -S --needed $MINGW_PACKAGE_PREFIX-clblast
  1. Build
cmake -B build -DWHISPER_CLBLAST=ON
cmake --build build -j16 --config Release

With OpenBLAS

  1. Install openblas
pacman -S --needed $MINGW_PACKAGE_PREFIX-openblas
  1. Build
export C_INCLUDE_PATH=${OPENBLAS_PATH}/include/openblas
export OPENBLAS_PATH=$MINGW_PREFIX
cmake -B build -DWHISPER_OPENBLAS=ON
cmake --build build -j16 --config Release

WIP: With Cuda

  1. Setup cuda
NAME=cuda_12.3.2_546.12_windows
pacman -S --needed $MINGW_PACKAGE_PREFIX-{7zip,wget}
wget -nc -q --show-progress https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/$NAME.exe
7z x -y -o$NAME $NAME.exe
mkdir -p $MINGW_PREFIX/opt/
mv $NAME $MINGW_PREFIX/opt/
  1. Build
NAME=cuda_12.3.2_546.12_windows
OPENBLAS_PATH=$MINGW_PREFIX cmake -B build -DWHISPER_CUBLAS=ON
cmake --build build -j16 --config Release

Hey can you help me with setup cause i have to show it into my college in few days and i cant solve error because i dont have much knowledge how can i change some things so my faculty cant find out that i

@fuzekun
Copy link

fuzekun commented Apr 20, 2024

When I run main.exe,it gives me error which the system loss file named libgcc_s_seh-1.dll. And After I have put the file into exact path,there was a new problems which the application could't run (0x000007b).

Simple way to build it on msys2 in Windows:

  1. Download msys2 from msys2.org
  2. open ucrt64.exe terminal
  3. Install presquites
    pacman -S --needed git $MINGW_PACKAGE_PREFIX-{cmake,ninja,toolchain}
    
  4. Clone and build
    git clone https://github.com/ggerganov/whisper.cpp
    cd whisper.cpp
    cmake -B build .
    cmake --build build -j16 --config Release
    
  5. Use it 🎉
    cd build/bin
    ./main.exe
    

With CLBlast

  1. Add CLBlast
pacman -S --needed $MINGW_PACKAGE_PREFIX-clblast
  1. Build
cmake -B build -DWHISPER_CLBLAST=ON
cmake --build build -j16 --config Release

With OpenBLAS

  1. Install openblas
pacman -S --needed $MINGW_PACKAGE_PREFIX-openblas
  1. Build
export C_INCLUDE_PATH=${OPENBLAS_PATH}/include/openblas
export OPENBLAS_PATH=$MINGW_PREFIX
cmake -B build -DWHISPER_OPENBLAS=ON
cmake --build build -j16 --config Release

WIP: With Cuda

  1. Setup cuda
NAME=cuda_12.3.2_546.12_windows
pacman -S --needed $MINGW_PACKAGE_PREFIX-{7zip,wget}
wget -nc -q --show-progress https://developer.download.nvidia.com/compute/cuda/12.3.2/local_installers/$NAME.exe
7z x -y -o$NAME $NAME.exe
mkdir -p $MINGW_PREFIX/opt/
mv $NAME $MINGW_PREFIX/opt/
  1. Build
NAME=cuda_12.3.2_546.12_windows
OPENBLAS_PATH=$MINGW_PREFIX cmake -B build -DWHISPER_CUBLAS=ON
cmake --build build -j16 --config Release

@saragonason
Copy link

Hi everyone,

i have tried the option with CUDA by @kaushal2012 "Simple way to build it on msys2 in Windows:"
But cmake dont see the downloaded CUDA from $MINGW_PREFIX/opt/

My Output is:

linko@msa-gaming UCRT64 /c/Users/linko/Desktop/ai/whisper.cpp
$ OPENBLAS_PATH=$MINGW_PREFIX cmake -B build -DWHISPER_CUBLAS=ON --fresh
-- Building for: Ninja
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/ucrt64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/ucrt64/bin/c .exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Git: C:/msys64/usr/bin/git.exe (found version "2.43.0")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Warning at CMakeLists.txt:320 (message):
WHISPER_CUBLAS is deprecated and will be removed in the future.

Use WHISPER_CUDA instead

-- Found CUDAToolkit: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/include (found version "12.4.99")
-- cuBLAS found
-- The CUDA compiler identification is NVIDIA 12.4.99
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - failed
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/nvcc.exe
-- Check for working CUDA compiler: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/nvcc.exe - broken
CMake Error at C:/msys64/ucrt64/share/cmake/Modules/CMakeTestCUDACompiler.cmake:59 (message):
The CUDA compiler

"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/bin/nvcc.exe"

is not able to compile a simple test program.

It fails with the following output:

Change Dir: 'C:/Users/linko/Desktop/ai/whisper.cpp/build/CMakeFiles/CMakeScratch/TryCompile-xd21hx'

Run Build Command(s): C:/msys64/ucrt64/bin/ninja.exe -v cmTC_3af12
[1/2] C:\PROGRA~1\NVIDIA~2\CUDA\v12.4\bin\nvcc.exe -forward-unknown-to-host-compiler   -D_WINDOWS -Xcompiler=" /GR /EHsc"  -Xcompiler=" -Zi -Ob0 -Od /RTC1" -Xcompiler=-MDd -MD -MT CMakeFiles\cmTC_3af12.dir\main.cu.obj -MF CMakeFiles\cmTC_3af12.dir\main.cu.obj.d -x cu -c C:\Users\linko\Desktop\ai\whisper.cpp\build\CMakeFiles\CMakeScratch\TryCompile-xd21hx\main.cu -o CMakeFiles\cmTC_3af12.dir\main.cu.obj -Xcompiler=-FdCMakeFiles\cmTC_3af12.dir\,-FS
main.cu
tmpxft_00002288_00000000-10_main.cudafe1.cpp
[2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\ucrt64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_3af12.dir --rc=C:\msys64\ucrt64\bin\windres.exe --mt="" --manifests  -- C:\msys64\ucrt64\bin\ld.exe /nologo CMakeFiles\cmTC_3af12.dir\main.cu.obj  /out:cmTC_3af12.exe /implib:cmTC_3af12.lib /pdb:cmTC_3af12.pdb /version:0.0 /debug /INCREMENTAL  cudadevrt.lib  cudart_static.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/lib/x64"  && cd ."
FAILED: cmTC_3af12.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\ucrt64\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_3af12.dir --rc=C:\msys64\ucrt64\bin\windres.exe --mt="" --manifests  -- C:\msys64\ucrt64\bin\ld.exe /nologo CMakeFiles\cmTC_3af12.dir\main.cu.obj  /out:cmTC_3af12.exe /implib:cmTC_3af12.lib /pdb:cmTC_3af12.pdb /version:0.0 /debug /INCREMENTAL  cudadevrt.lib  cudart_static.lib  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib -LIBPATH:"C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.4/lib/x64"  && cd ."
RC Pass 1: command "C:\msys64\ucrt64\bin\windres.exe /fo CMakeFiles\cmTC_3af12.dir/manifest.res CMakeFiles\cmTC_3af12.dir/manifest.rc" failed (exit code 1) with the following output:
Usage: C:\msys64\ucrt64\bin\windres.exe [option(s)] [input-file] [output-file]
 The options are:
  -i --input=<file>            Name input file
  -o --output=<file>           Name output file
  -J --input-format=<format>   Specify input format
  -O --output-format=<format>  Specify output format
  -F --target=<target>         Specify COFF target
     --preprocessor=<program>  Program to use to preprocess rc file
     --preprocessor-arg=<arg>  Additional preprocessor argument
  -I --include-dir=<dir>       Include directory when preprocessing rc file
  -D --define <sym>[=<val>]    Define SYM when preprocessing rc file
  -U --undefine <sym>          Undefine SYM when preprocessing rc file
  -v --verbose                 Verbose - tells you what it's doing
  -c --codepage=<codepage>     Specify default codepage
  -l --language=<val>          Set language when reading rc file
     --use-temp-file           Use a temporary file instead of popen to read
                               the preprocessor output
     --no-use-temp-file        Use popen (default)
  -r                           Ignored for compatibility with rc
  @<file>                      Read options from <file>
  -h --help                    Print this help message
  -V --version                 Print version information
FORMAT is one of rc, res, or coff, and is deduced from the file name
extension if not specified.  A single file name is an input file.
No input-file is stdin, default rc.  No output-file is stdout, default rc.
C:\msys64\ucrt64\bin\windres.exe: supported targets: pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 pe-i386 pei-i386 elf32-i386 elf32-iamcu pdb elf64-little elf64-big elf32-little elf32-big srec symbolsrec verilog tekhex binary ihex plugin
ninja: build stopped: subcommand failed.

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:332 (enable_language)

-- Configuring incomplete, errors occurred!

@Codereamp
Copy link

When I run main.exe,it gives me error which the system loss file named libgcc_s_seh-1.dll. And After I have put the file into exact path,there was a new problems which the application could't run (0x000007b).

For those unfamiliar, it's essential not only to compile the project inside msys2 shell (ucrt64) ,but also to use the main executable there, probably also assuming the path delimiter correction. It looks like you tried to run it outside msys2. So if you have a file c:\myfiles\mywav.wav then the command line inside ucrt64 should be

./main -m models/ggml-base.en.bin -f c:/myfiles/mywav.wav

@fuzekun
Copy link

fuzekun commented Apr 30, 2024

When I run main.exe,it gives me error which the system loss file named libgcc_s_seh-1.dll. And After I have put the file into exact path,there was a new problems which the application could't run (0x000007b).

For those unfamiliar, it's essential not only to compile the project inside msys2 shell (ucrt64) ,but also to use the main executable there, probably also assuming the path delimiter correction. It looks like you tried to run it outside msys2. So if you have a file c:\myfiles\mywav.wav then the command line inside ucrt64 should be

./main -m models/ggml-base.en.bin -f c:/myfiles/mywav.wav

Thank you, it worked. It was because I did not run it inside msys2. Since I can't run directly on Windows, I'll use Linux instead. Thank you again.

@thewh1teagle
Copy link
Contributor

thewh1teagle commented Apr 30, 2024

The disadvantages of using msys2, is that the binary won't run outside of that environment because it depended on msys2 DLLs.
The simplest way to compile whisper.cpp on Windows, is using msvc compiler (of Microsoft)

If you still need it, let me know and I'll provide instructions

@fuzekun
Copy link

fuzekun commented Apr 30, 2024

No need to trouble yourself anymore, I have successfully compiled on Linux. Thank you very much for your kind assistance.

The disadvantages of using msys2, is that the binary won't run outside of that environment because it depended on msys2 DLLs. The simplest way to compile whisper.cpp on Windows, is using msvc compiler (of Microsoft)

If you still need it, let me know and I'll provide instructions

@Codereamp
Copy link

Codereamp commented Apr 30, 2024

If you still need it, let me know and I'll provide instructions

@thewh1teagle, It would be great in general, preferably with command-line options and information about versions compatibility. Sometimes one can have some (ancient) msvc installed for some purpose in the past and it would be nice if some bat file with minor correction would also work with it.

@Codereamp
Copy link

The disadvantages of using msys2, is that the binary won't run outside of that environment because it depended on msys2 DLLs.

@thewh1teagle, I managed to make a static linking without much change to your routine, probably some minor questions along the way.

Basically there's an half-baked option WHISPER_STATIC in CMakeLists.txt, that can be used if @ggerganov finds time to do this consistently across the compilers. It's half-baked imho because it is not declared as a cmake option and used in mostly GPU logic branches of CMakeLists.txt.

Anyway, I added the following lines

if (WHISPER_STATIC)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
endif()

and the following steps (assuming you already compiled the project once. If not just skip cleaning: steps)

  • cleaning: Delete build/CMakeCache.txt
  • cmake -B build -DWHISPER_STATIC=ON. This step is similar to the instruction, only the option provided
  • cleaning: cmake --build build --target clean . I had to do this otherwise ninja said there's nothing to do. I don't know whether this expected or not but in another cmake-based project deletion of CMakeCache.txt and configure was enough to trigger the project rebuild.
  • cmake --build build -j16 --config Release (this one's is the same from the instruction)

The executable now starts in general Windows, without msys2 environment. It accepts windows-style paths (with backslash ""), but needs OEM encoding for non-latin parts of the paths.

The only big (for me) question left for me is that while inferring non-lating, the outputted text in the console is garbage no matter what the encodings I chose for the msys2 shell, and I see the same garbage in the windows console. The file output is always ok (UTF-8)

@Codereamp
Copy link

> 
> # WIP: With `Cuda`
> 
>     1. Setup `cuda`
>  ....
>     2. Build
> 
> 
> NAME=cuda_12.3.2_546.12_windows
> OPENBLAS_PATH=$MINGW_PREFIX cmake -B build -DWHISPER_CUBLAS=ON
> cmake --build build -j16 --config Release

@thewh1teagle, CUDA Build part probably no longer works for latest cmake (3.28.1). I already had a question to this part since the NAME variable is not mentioned anywhere in the following lines and OPENBLAS_PATH looks a little unrelated. What I managed to fix partly to make find_package(CUDAToolkit) happy is the second line replacement

CUDAToolkit_ROOT=$MINGW_PREFIX/opt/$NAME/cuda_nvcc/nvcc/ cmake -B build -DWHISPER_CUBLAS=ON -DCUDAToolkit_INCLUDE_DIRECTORIES=$MINGW_PREFIX/opt/$NAME/cuda_cudart/cudart/include -DCUDA_CUDART=$MINGW_PREFIX/opt/$NAME/cuda_cudart/cudart

now "cuBLAS found", but the script in the following lines can't detect CUDA architecture so I suspect I'm digging somewhere wrong (not to mentioning that my line is too long to look adequate).

Any thoughts?

@thewh1teagle
Copy link
Contributor

cmake -B build .
cmake --build build -j16 --config Release

I don't think it's possible to use CUDA when compiling inside msys2.

@thewh1teagle
Copy link
Contributor

now "cuBLAS found", but the script in the following lines can't detect CUDA architecture so I suspect I'm digging somewhere wrong (not to mentioning that my line is too long to look adequate).

Any thoughts?

I don't think it's possible to use CUDA when compiling inside msys2.

@Codereamp
Copy link

I don't think it's possible to use CUDA when compiling inside msys2.

I also met some short claims of impossibility, but now finally a notorious discussion about MinGW compatibility spanning 15 years, where the main fact is that nvcc.exe binary was and is hard-coded to cl.exe compiler (VC)

@BBC-Esq
Copy link

BBC-Esq commented May 30, 2024

The disadvantages of using msys2, is that the binary won't run outside of that environment because it depended on msys2 DLLs. The simplest way to compile whisper.cpp on Windows, is using msvc compiler (of Microsoft)

If you still need it, let me know and I'll provide instructions

I would appreciate detailed instructions on how to compile on Windows with msvc please...

@jralduaveuthey
Copy link

I am new to the party and probably this is a dumb question, but is there a .exe that I can just download and run in my windows machine?
preferably without going through all the messages posted here in the last 2 years :)

@Kishlay-notabot
Copy link

@Topping1

@Topping1 did you find a solution?

@BBC-Esq
Copy link

BBC-Esq commented Aug 16, 2024

I did not

@Kishlay-notabot
Copy link

can someone help me to compile stream.cpp for windows? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Build related issues
Projects
None yet
Development

No branches or pull requests