使用mingw64编译BUTT无法在赋值时将'char *'转换为'LPWSTR {aka wchar_t *}'

时间:2013-05-21 01:47:17

标签: windows winapi unicode mingw mingw-w64

我正在尝试使用MingwW64在Windows上编译BUTT(http://butt.sourceforge.net/)。我似乎最容易遇到类型error: cannot convert 'char*' to 'LPCWSTR {aka const wchar_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

这是第一个包含一些错误的函数:

// 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;
}
                         ^

1 个答案:

答案 0 :(得分:1)

有可能BUTT不是为Unicode而设计的,而是调用TCHAR的Win32 API函数 - 因为它们在编译时定义UNICODE / _UNICODE时使用Unicode,并且否则使用ANSI。因此要么进入你的项目设置,要么关闭 Unicode,这样这些API函数将使用ANSI,或者更新BUTT的代码为TCHAR - 同时也可以在{{{}}之间进行转换适当时1}}和char*