Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kou
Copy link
Contributor

@kou kou commented Apr 20, 2015

We get build errors when we build with the following configure on
Debian GNU/Linux:

% sudo apt-get install -y mingw-w64-x86-64-dev
% ./configure --prefix=/tmp/mecab --host=x86_64-w64-mingw32

Here are build errors:

In file included from tagger.cpp:15:0:
stream_wrapper.h: In constructor 'MeCab::ostream_wrapper::ostream_wrapper(const char*)':
stream_wrapper.h:49:46: error: no matching function for call to 'std::basic_ofstream<char>::basic_ofstream(const wchar_t*)'
       os_ = new std::ofstream(WPATH(filename));
                                              ^
stream_wrapper.h:49:46: note: candidates are:
In file included from stream_wrapper.h:10:0,
                 from tagger.cpp:15:
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
       basic_ofstream(const char* __s,
       ^
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const char*'
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
       basic_ofstream(): __ostream_type(), _M_filebuf()
       ^
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note:   candidate expects 0 arguments, 1 provided
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note: std::basic_ofstream<char>::basic_ofstream(const std::basic_ofstream<char>&)
     class basic_ofstream : public basic_ostream<_CharT,_Traits>
           ^
/usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const std::basic_ofstream<char>&'

These errors are caused because MinGW doesn't support wide stream
support streams. See also: http://www.mingw.org/wiki/wide_characters

WPATH_FORCE() is just for CreateFileW(). MinGW doesn't support wide
stream support streams but supports CreateFileW().

We get build errors when we build with the following configure on
Debian GNU/Linux:

    % sudo apt-get install -y mingw-w64-x86-64-dev
    % ./configure --prefix=/tmp/mecab --host=x86_64-w64-mingw32

Here are build errors:

    In file included from tagger.cpp:15:0:
    stream_wrapper.h: In constructor 'MeCab::ostream_wrapper::ostream_wrapper(const char*)':
    stream_wrapper.h:49:46: error: no matching function for call to 'std::basic_ofstream<char>::basic_ofstream(const wchar_t*)'
           os_ = new std::ofstream(WPATH(filename));
                                                  ^
    stream_wrapper.h:49:46: note: candidates are:
    In file included from stream_wrapper.h:10:0,
                     from tagger.cpp:15:
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
           basic_ofstream(const char* __s,
           ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const char*'
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
           basic_ofstream(): __ostream_type(), _M_filebuf()
           ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note:   candidate expects 0 arguments, 1 provided
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note: std::basic_ofstream<char>::basic_ofstream(const std::basic_ofstream<char>&)
         class basic_ofstream : public basic_ostream<_CharT,_Traits>
               ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const std::basic_ofstream<char>&'

These errors are caused because MinGW doesn't support wide stream
support streams. See also: http://www.mingw.org/wiki/wide_characters

WPATH_FORCE() is just for CreateFileW(). MinGW doesn't support wide
stream support streams but supports CreateFileW().
@kou
Copy link
Contributor Author

kou commented Apr 20, 2015

@taku910 We can use the following approach instead of this pull request approach. Which approach do you prefer?

diff --git a/mecab/src/common.h b/mecab/src/common.h
index 4ed43c9..a453269 100644
--- a/mecab/src/common.h
+++ b/mecab/src/common.h
@@ -81,7 +81,7 @@
 #define EXIT_SUCCESS 0
 #endif

-#if defined(_WIN32) && !defined(__CYGWIN__)
+#if defined(_WIN32) && !defined(__GNUC__)
 #define WPATH(path) (MeCab::Utf8ToWide(path).c_str())
 #else
 #define WPATH(path) (path)
diff --git a/mecab/src/mmap.h b/mecab/src/mmap.h
index 4ef8003..20d34cb 100644
--- a/mecab/src/mmap.h
+++ b/mecab/src/mmap.h
@@ -104,7 +104,8 @@ template <class T> class Mmap {
       CHECK_FALSE(false) << "unknown open mode:" << filename;
     }

-    hFile = ::CreateFileW(WPATH(filename), mode1, FILE_SHARE_READ, 0,
+    hFile = ::CreateFileW(MeCab::Utf8ToWide(filename).c_str(),
+                          mode1, FILE_SHARE_READ, 0,
                           OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
     CHECK_FALSE(hFile != INVALID_HANDLE_VALUE)
         << "CreateFile() failed: " << filename;

taku910 added a commit that referenced this pull request Feb 7, 2016
@taku910 taku910 merged commit 32041d9 into taku910:master Feb 7, 2016
@kou kou deleted the make-buildable-with-mingw branch February 7, 2016 15:04
Pusnow pushed a commit to Pusnow/mecab-ko-msvc that referenced this pull request Jun 29, 2017
We get build errors when we build with the following configure on
Debian GNU/Linux:

    % sudo apt-get install -y mingw-w64-x86-64-dev
    % ./configure --prefix=/tmp/mecab --host=x86_64-w64-mingw32

Here are build errors:

    In file included from tagger.cpp:15:0:
    stream_wrapper.h: In constructor 'MeCab::ostream_wrapper::ostream_wrapper(const char*)':
    stream_wrapper.h:49:46: error: no matching function for call to 'std::basic_ofstream<char>::basic_ofstream(const wchar_t*)'
           os_ = new std::ofstream(WPATH(filename));
                                                  ^
    stream_wrapper.h:49:46: note: candidates are:
    In file included from stream_wrapper.h:10:0,
                     from tagger.cpp:15:
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream(const char*, std::ios_base::openmode) [with _CharT = char; _Traits = std::char_traits<char>; std::ios_base::openmode = std::_Ios_Openmode]
           basic_ofstream(const char* __s,
           ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:643:7: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const char*'
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note: std::basic_ofstream<_CharT, _Traits>::basic_ofstream() [with _CharT = char; _Traits = std::char_traits<char>]
           basic_ofstream(): __ostream_type(), _M_filebuf()
           ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:628:7: note:   candidate expects 0 arguments, 1 provided
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note: std::basic_ofstream<char>::basic_ofstream(const std::basic_ofstream<char>&)
         class basic_ofstream : public basic_ostream<_CharT,_Traits>
               ^
    /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/c++/fstream:602:11: note:   no known conversion for argument 1 from 'const wchar_t*' to 'const std::basic_ofstream<char>&'

These errors are caused because MinGW doesn't support wide stream
support streams. See also: http://www.mingw.org/wiki/wide_characters

WPATH_FORCE() is just for CreateFileW(). MinGW doesn't support wide
stream support streams but supports CreateFileW().
#define WPATH_FORCE(path) (MeCab::Utf8ToWide(path).c_str())
#define WPATH(path) (path)
#else
#define WPATH(path) WPATH_FORCE(path)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou This change breaks building MSVC due to missing symbol WPATH_FORCE.

C:\Users\chezo\source\mecab\mecab\src>nmake -f Makefile.msvc

Microsoft(R) Program Maintenance Utility Version 14.16.27023.1
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl.exe /EHsc /O2 /GL /GA /Ob2 /nologo /W3 /MT /Zi /wd4800 /wd4305 /wd4244 -I. -I.. -D_CRT_SECURE_NO_DEPRECATE -DMECAB_USE_THREAD  -DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=@DIC_VERSION@  -DVERSION="\"@VERSION@\"" -DPACKAGE="\"mecab\""  -DUNICODE -D_UNICODE  -DMECAB_DEFAULT_RC="\"c:\\Program Files\\mecab\\etc\\mecabrc\"" -c  feature_index.cpp
feature_index.cpp
feature_index.cpp(80): error C3861: 'WPATH_FORCE': 識別子が見つかりませんでした
feature_index.cpp(356): error C2593: 'operator <<' があいまいです。
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(55): note: 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(unsigned char)' の可能性があります
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(51): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(char)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(46): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(unsigned long)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(45): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(unsigned int)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(44): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(unsigned short)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(43): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(long)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(42): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(int)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(41): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(short)'
c:\users\chezo\source\mecab\mecab\src\string_buffer.h(40): note: または 'MeCab::StringBuffer &MeCab::StringBuffer::operator <<(double)'
feature_index.cpp(356): note: 引数リスト '(MeCab::StringBuffer, size_t)' を一致させようとしているとき
feature_index.cpp(454): warning C4267: 'return': 'size_t' から 'int' に変換しました。データが失われているかもしれません。
feature_index.cpp(532): error C3861: 'WPATH_FORCE': 識別子が見つかりませんでした
feature_index.cpp(540): error C3861: 'WPATH_FORCE': 識別子が見つかりませんでした
feature_index.cpp(621): error C3861: 'WPATH_FORCE': 識別子が見つかりませんでした
feature_index.cpp(672): error C3861: 'WPATH_FORCE': 識別子が見つかりませんでした
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe"' : リターン コード '0x2'
Stop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry.
We should have been defined WPATH_FORCE out of #ifdef __GNUC__.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense. I'll fix as you intended.

GerHobbelt pushed a commit to GerHobbelt/mecab that referenced this pull request May 13, 2025
Fix handling of node-format when output-format-type is set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants