Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make buildable MSVC 64bit #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions mecab/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.obj
*.exe
*.lib
*.so
*.pyc
*.exp
*.pyc
*.dll
*.pdb
python/build
python/dist
python/*.egg-info
python/.venv
python/venv
.vs
53 changes: 53 additions & 0 deletions mecab/src/Makefile.x64.msvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
CC = cl.exe
CXXC = cl.exe
LINK=link.exe

CFLAGS = /EHsc /O2 /GL /GA /Ob2 /nologo /W3 /MT /Zi /wd4800 /wd4305 /wd4244
LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X64 ADVAPI32.LIB
DEFS = -D_CRT_SECURE_NO_DEPRECATE -DMECAB_USE_THREAD \
-DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=102 \
-DVERSION="\"0.996\"" -DPACKAGE="\"mecab\"" \
-DUNICODE -D_UNICODE \
-DMECAB_DEFAULT_RC="\"c:\\Program Files\\mecab\\etc\\mecabrc\""
INC = -I. -I..
DEL = del

OBJ = feature_index.obj param.obj learner.obj string_buffer.obj \
char_property.obj learner_tagger.obj tagger.obj \
connector.obj tokenizer.obj \
context_id.obj dictionary.obj utils.obj \
dictionary_compiler.obj viterbi.obj \
dictionary_generator.obj writer.obj iconv_utils.obj \
dictionary_rewriter.obj lbfgs.obj eval.obj nbest_generator.obj

.c.obj:
$(CC) $(CFLAGS) $(INC) $(DEFS) -c $<

.cpp.obj:
$(CC) $(CFLAGS) $(INC) $(DEFS) -c $<

all: libmecab mecab mecab-dict-index mecab-dict-gen mecab-cost-train mecab-system-eval mecab-test-gen

mecab: $(OBJ) mecab.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab.obj libmecab.lib

mecab-dict-index: $(OBJ) mecab-dict-index.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-dict-index.obj libmecab.lib

mecab-dict-gen: $(OBJ) mecab-dict-gen.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-dict-gen.obj libmecab.lib

mecab-cost-train: $(OBJ) mecab-cost-train.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-cost-train.obj libmecab.lib

mecab-system-eval: $(OBJ) mecab-system-eval.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-system-eval.obj libmecab.lib

mecab-test-gen: mecab-test-gen.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-test-gen.obj libmecab.lib

libmecab: $(OBJ) libmecab.obj
$(LINK) $(LDFLAGS) /out:[email protected] $(OBJ) libmecab.obj /dll

clean:
$(DEL) *.exe *.obj *.dll *.a *.lib *.o *.exp *.def
53 changes: 53 additions & 0 deletions mecab/src/Makefile.x86.msvc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
CC = cl.exe
CXXC = cl.exe
LINK=link.exe

CFLAGS = /EHsc /O2 /GL /GA /Ob2 /nologo /W3 /MT /Zi /wd4800 /wd4305 /wd4244
LDFLAGS = /nologo /OPT:REF /OPT:ICF /LTCG /NXCOMPAT /DYNAMICBASE /MACHINE:X86 ADVAPI32.LIB
DEFS = -D_CRT_SECURE_NO_DEPRECATE -DMECAB_USE_THREAD \
-DDLL_EXPORT -DHAVE_GETENV -DHAVE_WINDOWS_H -DDIC_VERSION=102 \
-DVERSION="\"0.996\"" -DPACKAGE="\"mecab\"" \
-DUNICODE -D_UNICODE \
-DMECAB_DEFAULT_RC="\"c:\\Program Files\\mecab\\etc\\mecabrc\""
INC = -I. -I..
DEL = del

OBJ = feature_index.obj param.obj learner.obj string_buffer.obj \
char_property.obj learner_tagger.obj tagger.obj \
connector.obj tokenizer.obj \
context_id.obj dictionary.obj utils.obj \
dictionary_compiler.obj viterbi.obj \
dictionary_generator.obj writer.obj iconv_utils.obj \
dictionary_rewriter.obj lbfgs.obj eval.obj nbest_generator.obj

.c.obj:
$(CC) $(CFLAGS) $(INC) $(DEFS) -c $<

.cpp.obj:
$(CC) $(CFLAGS) $(INC) $(DEFS) -c $<

all: libmecab mecab mecab-dict-index mecab-dict-gen mecab-cost-train mecab-system-eval mecab-test-gen

mecab: $(OBJ) mecab.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab.obj libmecab.lib

mecab-dict-index: $(OBJ) mecab-dict-index.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-dict-index.obj libmecab.lib

mecab-dict-gen: $(OBJ) mecab-dict-gen.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-dict-gen.obj libmecab.lib

mecab-cost-train: $(OBJ) mecab-cost-train.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-cost-train.obj libmecab.lib

mecab-system-eval: $(OBJ) mecab-system-eval.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-system-eval.obj libmecab.lib

mecab-test-gen: mecab-test-gen.obj
$(LINK) $(LDFLAGS) /out:[email protected] mecab-test-gen.obj libmecab.lib

libmecab: $(OBJ) libmecab.obj
$(LINK) $(LDFLAGS) /out:[email protected] $(OBJ) libmecab.obj /dll

clean:
$(DEL) *.exe *.obj *.dll *.a *.lib *.o *.exp *.def
7 changes: 2 additions & 5 deletions mecab/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#if defined(_MSC_VER) || defined(__CYGWIN__)
#define NOMINMAX
#define snprintf _snprintf
#include <iterator>
#endif

#define COPYRIGHT "MeCab: Yet Another Part-of-Speech and Morphological Analyzer\n\
Expand Down Expand Up @@ -81,13 +82,9 @@
#define EXIT_SUCCESS 0
#endif

#ifdef _WIN32
#ifdef __GNUC__
#if defined(_WIN32) && (defined(__GNUC__) || defined(_MSC_VER))
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to convert path to wide characters from UTF-8 when we use WPATH_FORCE on both GCC and MSVC.

Copy link
Author

@chezou chezou Nov 24, 2018

Choose a reason for hiding this comment

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

@kou Fixed on 28f7de4 . Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes!

#define WPATH_FORCE(path) (MeCab::Utf8ToWide(path).c_str())
#define WPATH(path) (path)
#else
#define WPATH(path) WPATH_FORCE(path)
#endif
#else
#define WPATH_FORCE(path) (path)
#define WPATH(path) (path)
Expand Down
2 changes: 1 addition & 1 deletion mecab/src/feature_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool FeatureIndex::buildUnigramFeature(LearnerPath *path,
if (!r) goto NEXT;
os_ << r;
} break;
case 't': os_ << (size_t)path->rnode->char_type; break;
case 't': os_ << (unsigned int)path->rnode->char_type; break;
case 'u': os_ << ufeature; break;
case 'w':
if (path->rnode->stat == MECAB_NOR_NODE) {
Expand Down
2 changes: 1 addition & 1 deletion mecab/src/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ bool Writer::writeNode(Lattice *lattice,
// input sentence
case 'S': os->write(lattice->sentence(), lattice->size()); break;
// sentence length
case 'L': *os << lattice->size(); break;
case 'L': *os << (unsigned int)lattice->size(); break;
// morph
case 'm': os->write(node->surface, node->length); break;
case 'M': os->write(reinterpret_cast<const char *>
Expand Down