Windows 使用mingw64编译BUTT无法转换';字符*';至';LPWSTR{aka wchar_t*}';委派

Windows 使用mingw64编译BUTT无法转换';字符*';至';LPWSTR{aka wchar_t*}';委派,windows,winapi,unicode,mingw,mingw-w64,Windows,Winapi,Unicode,Mingw,Mingw W64,我正在尝试使用MingwW64在windows上编译BUTT()。我似乎遇到了类型为的错误:无法将'char*'转换为'LPCWSTR{aka const wchar\u t*}'的错误最多。是否有一些我缺少的简单的启用unicode的选项?您可以在“我的粘贴”的顶部看到传递给g++的选项 0_0@0_0-PC /z/src/butt-0.1.12 $ make make -C src check for ../config.mk ... ok. make[1]: Entering direct

我正在尝试使用MingwW64在windows上编译BUTT()。我似乎遇到了类型为
的错误:无法将'char*'转换为'LPCWSTR{aka const wchar\u t*}'
的错误最多。是否有一些我缺少的简单的启用unicode的选项?您可以在“我的粘贴”的顶部看到传递给g++的选项

0_0@0_0-PC /z/src/butt-0.1.12
$ make
make -C src
check for ../config.mk ...
ok.
make[1]: Entering directory `/z/src/butt-0.1.12/src'
g++  -I/usr/local/include -I/usr/local/include -I/usr/local/include  -I. -I/usr/
local/include -Wall -O2 -DVERSION=\"butt-0.1.12\" `` -IFLTK  -I/usr/local/includ
e -I/usr/local/include/FL/images -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_S
OURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -DFLTK1 -DHAVE_FLTK -ILIBVORB
IS   -DHAVE_LIBVORBIS -ILIBLAME   -DHAVE_LIBLAME   -c -o FLTK/Fl_Native_File_Cho
oser.o FLTK/Fl_Native_File_Chooser.cpp
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx: In member function 'void Fl_Native_File_C
hooser::ClearOFN()':
FLTK/Fl_Native_File_Chooser_WIN32.cxx:244:24: error: cannot convert 'char*' to '
LPWSTR {aka wchar_t*}' in assignment
         _ofn.lpstrFile = strfree((char*)_ofn.lpstrFile);
                        ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:247:30: error: cannot convert 'LPCSTR {aka
 const char*}' to 'LPCWSTR {aka const wchar_t*}' in assignment
         _ofn.lpstrInitialDir = (LPCSTR)strfree((char*)_ofn.lpstrInitialDir);
                              ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx: In member function 'int Fl_Native_File_Ch
ooser::showfile()':
FLTK/Fl_Native_File_Chooser_WIN32.cxx:312:23: error: cannot convert 'char*' to '
LPWSTR {aka wchar_t*}' in assignment
     _ofn.lpstrFile    = new char[fsize];
                       ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:319:21: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' in assignment
     _ofn.lpstrTitle = _title ? _title : NULL;
                     ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:321:22: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' in assignment
     _ofn.lpstrFilter = _parsedfilt ? _parsedfilt : NULL;
                      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:333:53: error: cannot convert 'LPWSTR {aka
 wchar_t*}' to 'char*' for argument '1' to 'char* strncpy(char*, const char*, si
ze_t)'
  strncpy(_ofn.lpstrFile, _preset_file, _ofn.nMaxFile);
                                                     ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:334:25: error: no matching function for ca
ll to 'Fl_Native_File_Chooser::Unix2Win(WCHAR*&)'
  Unix2Win(_ofn.lpstrFile);
                         ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:334:25: note: candidate is:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note: void Fl_Native_File_Chooser::
Unix2Win(char*)
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:272:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::Unix2Win(char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note:   no known conversion for arg
ument 1 from 'LPWSTR {aka wchar_t*}' to 'char*'
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:272:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::Unix2Win(char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:343:23: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' in assignment
  _ofn.lpstrInitialDir = strnew(_directory);
                       ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:352:41: error: cannot convert 'char*' to '
LPWSTR {aka wchar_t*}' for argument '2' to 'DWORD GetCurrentDirectoryW(DWORD, LP
WSTR)'
     GetCurrentDirectory(MAX_PATH, oldcwd);
                                         ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:372:45: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' for argument '1' to 'WINBOOL SetCurrentDirectoryW(
LPCWSTR)'
  if ( oldcwd[0] ) SetCurrentDirectory(oldcwd);
                                             ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:377:35: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' for argument '1' to 'WINBOOL SetCurrentDirectoryW(
LPCWSTR)'
         SetCurrentDirectory(oldcwd);
                                   ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:383:40: error: no matching function for ca
ll to 'Fl_Native_File_Chooser::set_single_pathname(WCHAR*&)'
      set_single_pathname(_ofn.lpstrFile);
                                        ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:383:40: note: candidate is:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note: void Fl_Native_File_Chooser::
set_single_pathname(const char*)
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:208:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::set_single_pathname(const char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note:   no known conversion for arg
ument 1 from 'LPWSTR {aka wchar_t*}' to 'const char*'
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:208:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::set_single_pathname(const char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:388:33: error: cannot convert 'LPWSTR {aka
 wchar_t*}' to 'const char*' in initialization
      const char *dirname = _ofn.lpstrFile;
                                 ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:395:51: error: cannot convert 'LPWSTR {aka
 wchar_t*}' to 'const char*' in initialization
   for ( const char *s = _ofn.lpstrFile + dirlen + 1;
                                                   ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx: In member function 'int Fl_Native_File_Ch
ooser::showdir()':
FLTK/Fl_Native_File_Chooser_WIN32.cxx:460:21: error: cannot convert 'char*' to '
LPCWSTR {aka const wchar_t*}' in assignment
     _binf.lpszTitle = _title ? _title : NULL;
                     ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:483:26: error: cannot convert 'char [260]'
 to 'LPWSTR {aka wchar_t*}' in assignment
     _binf.pszDisplayName = displayname;
                          ^
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:504:22: error: no matching function for ca
ll to 'Fl_Native_File_Chooser::Win2Unix(TCHAR [260])'
         Win2Unix(path);
                      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:504:22: note: candidate is:
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note: void Fl_Native_File_Chooser::
Win2Unix(char*)
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:266:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::Win2Unix(char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note:   no known conversion for arg
ument 1 from 'TCHAR [260] {aka wchar_t [260]}' to 'char*'
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:266:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::Win2Unix(char *s) {
      ^
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:505:19: error: no matching function for ca
ll to 'Fl_Native_File_Chooser::add_pathname(TCHAR [260])'
  add_pathname(path);
                   ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:505:19: note: candidate is:
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note: void Fl_Native_File_Chooser::
add_pathname(const char*)
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:216:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::add_pathname(const char *s) {
      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:42:20: note:   no known conversion for arg
ument 1 from 'TCHAR [260] {aka wchar_t [260]}' to 'const char*'
 #define FNFC_CLASS Fl_Native_File_Chooser
                    ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:216:6: note: in expansion of macro 'FNFC_C
LASS'
 void FNFC_CLASS::add_pathname(const char *s) {
      ^
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:508:22: error: cannot convert 'TCHAR* {aka
 wchar_t*}' to 'const char*' for argument '1' to 'size_t strlen(const char*)'
     if ( !strlen(path) ) return(1);             // don't return empty pathnames

                      ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx: In member function 'void Fl_Native_File_C
hooser::add_filter(const char*, const char*)':
FLTK/Fl_Native_File_Chooser_WIN32.cxx:617:56: warning: field precision specifier
 '.*' expects argument of type 'int', but argument 3 has type 'long long unsigne
d int' [-Wformat=]
  sprintf(name, "%.*s Files", sizeof(name)-10, winfilter);
                                                        ^
FLTK/Fl_Native_File_Chooser_WIN32.cxx:619:55: warning: field precision specifier
 '.*' expects argument of type 'int', but argument 3 has type 'long long unsigne
d int' [-Wformat=]
         sprintf(name, "%.*s", sizeof(name)-10, name_in);
                                                       ^
In file included from FLTK/Fl_Native_File_Chooser_WIN32.cxx:35:0,
                 from FLTK/Fl_Native_File_Chooser.cpp:26:
FLTK/Fl_Native_File_Chooser_common.cxx: At global scope:
FLTK/Fl_Native_File_Chooser_common.cxx:60:14: warning: 'char* strapp(char*, cons
t char*)' defined but not used [-Wunused-function]
 static char *strapp(char *s, const char *val) {
              ^
In file included from FLTK/Fl_Native_File_Chooser.cpp:26:0:
FLTK/Fl_Native_File_Chooser_WIN32.cxx:61:13: warning: 'void dnullprint(char*)' d
efined but not used [-Wunused-function]
 static void dnullprint(char *wp) {
             ^
<builtin>: recipe for target `FLTK/Fl_Native_File_Chooser.o' failed
make[1]: *** [FLTK/Fl_Native_File_Chooser.o] Error 1
make[1]: Leaving directory `/z/src/butt-0.1.12/src'
Makefile:48: recipe for target `butt' failed
make: *** [butt] Error 2

很可能BUTT不是为Unicode设计的,而是调用支持
TCHAR
的Win32 API函数,因此在编译期间定义
Unicode
/
\u Unicode
时使用Unicode,否则使用ANSI。因此,要么进入项目设置并关闭Unicode,这样API函数就会使用ANSI,或者将BUTT的代码更新为
TCHAR
-感知,以便它可以在适当的时候在
char*
wchar\u t*
之间进行转换。

如果您不显示导致错误的代码,这些错误消息就没有多大帮助。哦,好吧,我想可能是另一种方式。Butt没有在任何地方定义UNICODE。是的,您在项目中定义了
UNICODE
\ofn
是一个
OPENFILENAME
结构,其字符串成员使用
TCHAR
,当定义
UNICODE
时,它就是
wchar\t
。BUTT的代码正在对
char*
执行一些硬编码类型转换,这一事实告诉我,它知道
OPENFILENAME
使用
TCHAR
,并且在不应该的时候忽略了这一事实。特别是,对
strfree()
的调用需要用
TCHAR
感知的东西替换,对
new char[]
的调用需要替换为
new TCHAR[]
strncpy()
替换为
lstrcpy()
,等等。否则,如果不想更改BUTT的代码,需要为整个项目关闭
UNICODE
。在项目设置中有一个选项。我使用的是Mingw-w64,所以我不确定如何关闭UNICODE?
// CLEAR MICROSOFT OFN (OPEN FILE NAME) CLASS
void FNFC_CLASS::ClearOFN() {
    // Free any previously allocated lpstrFile before zeroing out _ofn
    if ( _ofn.lpstrFile ) {
        _ofn.lpstrFile = strfree((char*)_ofn.lpstrFile);
    }
    if ( _ofn.lpstrInitialDir ) {
        _ofn.lpstrInitialDir = (LPCSTR)strfree((char*)_ofn.lpstrInitialDir);
    }
    _ofn.lpstrFilter = NULL;        // (deleted elsewhere)
    int temp = _ofn.nFilterIndex;   // keep the filter_value
    memset((void*)&_ofn, 0, sizeof(_ofn));
    _ofn.lStructSize  = sizeof(OPENFILENAME);
    _ofn.nFilterIndex = temp;
}
                         ^