Skip to content

Commit d682e15

Browse files
foldlJudd
and
Judd
authored
Fixes for Windows (#2790)
Fixes for Windows: * MSVC default to utf-8 without BOM. * Console output code page changed to utf-8. --------- Co-authored-by: Judd <[email protected]>
1 parent 46d07b9 commit d682e15

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cmake/build-info.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ endif()
4242
if(MSVC)
4343
set(BUILD_COMPILER "${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION}")
4444
set(BUILD_TARGET ${CMAKE_VS_PLATFORM_NAME})
45+
add_compile_options("$<$<COMPILE_LANGUAGE:C>:/utf-8>")
46+
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/utf-8>")
4547
else()
4648
execute_process(
4749
COMMAND sh -c "$@ --version | head -1" _ ${CMAKE_C_COMPILER}

examples/cli/cli.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
#include <vector>
1313
#include <cstring>
1414

15+
#if defined(_WIN32)
16+
#define NOMINMAX
17+
#include <windows.h>
18+
#endif
19+
1520
#if defined(_MSC_VER)
1621
#pragma warning(disable: 4244 4267) // possible loss of data
1722
#endif
@@ -916,6 +921,13 @@ static bool output_lrc(struct whisper_context * ctx, const char * fname, const w
916921
static void cb_log_disable(enum ggml_log_level , const char * , void * ) { }
917922

918923
int main(int argc, char ** argv) {
924+
#if defined(_WIN32)
925+
// Set the console output code page to UTF-8, while command line arguments
926+
// are still encoded in the system's code page. In this way, we can print
927+
// non-ASCII characters to the console, and access files with non-ASCII paths.
928+
SetConsoleOutputCP(CP_UTF8);
929+
#endif
930+
919931
whisper_params params;
920932

921933
// If the only argument starts with "@", read arguments line-by-line

0 commit comments

Comments
 (0)