-
Notifications
You must be signed in to change notification settings - Fork 16
64 Bit Windows
The MeCab Binary package for MS-Windows works fine when using a 32-bit build of Ruby for Windows.
But you may encounter problems as soon as you try using a 64-bit Windows Ruby with MeCab.
When using a 64-bit Ruby for Windows (x64-mingw32
) or JRuby Windows executable x64 (Windows n-amd64
) with the 32-bit build of mecab on Windows,
the ffi
binding will throw up mysterious and uninformative errors.
irb(main):001:0> ENV['MECAB_PATH']='C:\\Program Files (x86)\\MeCab\\bin\\libmecab.dll'
irb(main):002:0> require 'natto'
LoadError: Could not open library 'C:\Program Files (x86)\MeCab\bin\libmecab.dll': iM
from C:/Ruby/Ruby200-x64/lib/ruby/gems/2.0.0/gems/ffi-1.9.6-x64-mingw32/lib/ffi/
library.rb:133:in `block in ffi_lib'
The solution is to build a 64-bit libmecab.dll, which we will use instead of the 32-bit libmecab.dll in your existing MeCab installation.
This is a bit involved, but stick with me.
-
Download the Visual Studio 2015 Community Edition. During installation, select the Custom option to install Visual C++ (under Programming Languages).
-
If you haven't done so already, download and install the MeCab Binary package for MS-Windows. This will also install the required
mecab-ipadic
system dictionary. -
Download the MeCab source mecab-0.996.tar.gz. Save to some temporary working folder, for example
C:\temp\MeCab
. -
Untar
mecab-0.996.tar.gz
, and cd intomecab-0.996\src
. -
Patch for
feature_index.cpp
:# line 356, change cast from size_t to unsigned int before: case 't': os_ << (size_t)path->rnode->char_type; break; after: case 't': os_ << (unsigned int)path->rnode->char_type; break; ^^^^^^^^^^^^
-
Patch for
writer.cpp
:# line 260, add cast to unsigned int before: case 'L': *os << lattice->size(); break; after: case 'L': *os << (unsigned int)lattice->size(); break; ^^^^^^^^^^^^
-
Patch for
utils.h
:# line 27, comment out unnecessary typedef for uint32_t before: typedef unsigned long uint32_t; after: /*typedef unsigned long uint32_t;*/
-
Patch for
Makefile.msvc.in
:# line 6, set machine flag to X64 before: LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X86 ADVAPI32.LIB after: LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X64 ADVAPI32.LIB ^^^ # line 8, explicitly set DIC_VERSION value before: -DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=@DIC_VERSION@ \ after: -DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=102 \ ^^^ # next, at line 9, explicitly set VERSION value before: -DVERSION="\"@VERSION@\"" -DPACKAGE="\"mecab\"" \ after: -DVERSION="\"0.996\"" -DPACKAGE="\"mecab\"" \ ^^^^^ # finally, at line 11, change the default path to mecabrc before: -DMECAB_DEFAULT_RC="\"c:\\Program Files\\mecab\\etc\\mecabrc\"" after: -DMECAB_DEFAULT_RC="\"C:\\Program Files (x86)\\mecab\\etc\\mecabrc\"" ^^^^^^^^^^^^^^^^^^^^^^^
-
Set environment variables for building 64-bit libmecab.dll. Open up a Windows
cmd
window in themecab-0.996\src
folder, and execute:call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64\vcvarsx86_amd64.bat"
-
Next, from that same
cmd
window opened tomecab-0.996\src
, executenmake
and buildlibmecab.dll
:nmake -f Makefile.msvc.in
-
Copy the resulting
mecab-0.996\src\libmecab.dll
and.exe
files to your MeCab installation'sbin
dir (back up this folder beforehand, if you need to. Alternately, you could save the newly-built 64-bitlibmecab.dll
elsewhere, and use theMECAB_PATH
environment variable to reference it.
References:
- http://qiita.com/ykchat/items/97dd7be100bfa837b7c4
- http://blog.yujigraffiti.com/2013/12/mecab-python-0999windows-64bit.html