Skip to content

Instantly share code, notes, and snippets.

@mugwort-rc
Last active February 27, 2017 15:46
Show Gist options
  • Save mugwort-rc/14b43db580970975059534abba1b97cf to your computer and use it in GitHub Desktop.
Save mugwort-rc/14b43db580970975059534abba1b97cf to your computer and use it in GitHub Desktop.
MeCab 0.996 with Boost.Iostreams on MSYS2/MinGW32

MeCab Windows版ではstd::fstream::fstream(const wchar_t *)という非標準のMSVC仕様を使用しており、MinGWでビルドができないことが不満だったため、強引にBoost.Iostreamsを使用してみました。

コンパイルが通ることはMSYS2のMinGW32でのみ確認しています。

  • 01.diff.patch
  • 02.mecab.h.patch
  • 03.config.h.patch
  • 04.Makefile.patch

01から順番にパッチを当ててください。

git版(32041d9)で作成したパッチのため、アーカイブ版(mecab-0.996.tar.gz)に適用する場合はpatch -p2 01.diff.patchとしてください。

なお、03と04はconfigureにより生成されたファイルに追記しますので、適宜読み替えて適用した方がよいでしょう。

04においてはboost 1.63を使用しておりますので、ご自身の環境に合わせてご使用ください。

このpatchを使用したことで生じた不具合等は関知いたしませんので、自己責任でご使用ください。

修正等ありましたら@mugwort_rc宛に教えていただけると幸いです。

※ANSI関数にダウングレードすることで無理やりMinGW(www.mingw.org 版)でビルドするパッチ: https://gist.github.com/mugwort-rc/25d1be5b81b1234417aa

diff --git a/mecab/src/char_property.cpp b/mecab/src/char_property.cpp
index f78dacb..336456a 100644
--- a/mecab/src/char_property.cpp
+++ b/mecab/src/char_property.cpp
@@ -135,17 +135,32 @@ bool CharProperty::compile(const char *cfile,
std::vector<Range> range;
std::map<std::string, CharInfo> category;
std::vector<std::string> category_ary;
- std::ifstream ifs(WPATH(cfile));
std::istringstream iss(CHAR_PROPERTY_DEF_DEFAULT);
- std::istream *is = &ifs;
+#ifdef HAVE_BOOST
+ boost::filesystem::path path(WPATH(cfile));
+ boost::filesystem::ifstream ifs(path);
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> ifilter;
+
+ if (!ifs.is_open()) {
+ std::cerr << cfile
+ << " is not found. minimum setting is used" << std::endl;
+ ifilter.push(iss);
+ } else {
+ ifilter.push(ifs);
+ }
+ std::istream is(&ifilter);
+#else
+ std::ifstream ifs(WPATH(cfile));
+ std::istream &is = ifs;
if (!ifs) {
std::cerr << cfile
<< " is not found. minimum setting is used" << std::endl;
- is = &iss;
+ is = iss;
}
+#endif
- while (is->getline(line.get(), line.size())) {
+ while (is.getline(line.get(), line.size())) {
if (std::strlen(line.get()) == 0 || line[0] == '#') {
continue;
}
@@ -211,17 +226,32 @@ bool CharProperty::compile(const char *cfile,
<< "category [SPACE] is undefined";
std::istringstream iss2(UNK_DEF_DEFAULT);
+#ifdef HAVE_BOOST
+ boost::filesystem::path path2(WPATH(ufile));
+ boost::filesystem::ifstream ifs2(path2);
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> ofilter;
+
+ if (!ifs2.is_open()) {
+ std::cerr << ufile
+ << " is not found. minimum setting is used." << std::endl;
+ ofilter.push(iss2);
+ } else {
+ ofilter.push(ifs2);
+ }
+ std::istream is2(&ofilter);
+#else
std::ifstream ifs2(WPATH(ufile));
- std::istream *is2 = &ifs2;
+ std::istream &is2 = ifs2;
if (!ifs2) {
std::cerr << ufile
<< " is not found. minimum setting is used." << std::endl;
- is2 = &iss2;
+ is2 = iss2;
}
+#endif
std::set<std::string> unk;
- while (is2->getline(line.get(), line.size())) {
+ while (is2.getline(line.get(), line.size())) {
const size_t n = tokenizeCSV(line.get(), col.get(), 2);
CHECK_DIE(n >= 1) << "format error: " << line.get();
const std::string key = col[0];
@@ -256,7 +286,11 @@ bool CharProperty::compile(const char *cfile,
// output binary table
{
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out);
+#else
std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out);
+#endif
CHECK_DIE(ofs) << "permission denied: " << ofile;
unsigned int size = static_cast<unsigned int>(category.size());
diff --git a/mecab/src/common.h b/mecab/src/common.h
index d1fc459..9b5a53d 100644
--- a/mecab/src/common.h
+++ b/mecab/src/common.h
@@ -23,6 +23,116 @@
#include "config.h"
#endif
+#ifdef HAVE_BOOST
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/fstream.hpp>
+#include <boost/iostreams/filtering_streambuf.hpp>
+
+class iostreams_ifstream
+{
+public:
+ iostreams_ifstream(const char *filename,
+ std::ios_base::openmode mode=std::ios::in) :
+ iostreams_ifstream(boost::filesystem::path(filename), mode)
+ {}
+
+ iostreams_ifstream(const wchar_t *filename,
+ std::ios_base::openmode mode=std::ios::in) :
+ iostreams_ifstream(boost::filesystem::path(filename), mode)
+ {}
+
+ iostreams_ifstream(const boost::filesystem::path &path,
+ std::ios_base::openmode mode) :
+ ifs(path, mode),
+ filter(ifs),
+ is_(new std::istream(&filter))
+ {}
+
+ std::istream &operator*() const { return *is_; }
+ std::istream *operator->() const { return is_; }
+ std::istream *operator&() const { return is_; }
+
+ operator bool() const {
+ return ifs.is_open();
+ }
+ operator std::istream &() const { return *is_; }
+
+ void close() { ifs.close(); }
+
+ std::istream &getline(char *s, std::streamsize n) {
+ return is_->getline(s, n);
+ }
+
+ boost::filesystem::ifstream ifs;
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter;
+ std::istream *is_;
+};
+
+template <class T>
+std::istream& operator >>(iostreams_ifstream &os, T &dt)
+{
+ return (*os) >> dt;
+}
+
+namespace std {
+inline std::istream &getline(iostreams_ifstream &is, std::string &s) {
+ return std::getline((*is), s);
+}
+}
+
+class iostreams_ofstream
+{
+public:
+ iostreams_ofstream(const char *filename,
+ std::ios_base::openmode mode=std::ios::out) :
+ iostreams_ofstream(boost::filesystem::path(filename), mode)
+ {}
+
+ iostreams_ofstream(const wchar_t *filename,
+ std::ios_base::openmode mode=std::ios::out) :
+ iostreams_ofstream(boost::filesystem::path(filename), mode)
+ {}
+
+ iostreams_ofstream(const boost::filesystem::path &path,
+ std::ios_base::openmode mode) :
+ ofs(path, mode),
+ filter(ofs),
+ os_(new std::ostream(&filter))
+ {}
+
+ std::ostream &operator*() const { return *os_; }
+ std::ostream *operator->() const { return os_; }
+ std::ostream *operator&() const { return os_; }
+
+ operator bool() const {
+ return ofs.is_open();
+ }
+
+ void close() { ofs.close(); }
+
+ std::size_t tellp() {
+ return os_->tellp();
+ }
+ std::ostream &seekp(std::size_t pos) {
+ return os_->seekp(pos);
+ }
+
+ std::ostream &write(const char *s, std::streamsize n) {
+ return os_->write(s, n);
+ }
+
+ boost::filesystem::ofstream ofs;
+ boost::iostreams::filtering_streambuf<boost::iostreams::output> filter;
+ std::ostream *os_;
+};
+
+template <class T>
+std::ostream& operator <<(iostreams_ofstream &os, const T &dt)
+{
+ return (*os) << dt;
+}
+#endif
+
#if defined(_MSC_VER) || defined(__CYGWIN__)
#define NOMINMAX
#define snprintf _snprintf
diff --git a/mecab/src/connector.cpp b/mecab/src/connector.cpp
index 4021cbe..f718d4b 100644
--- a/mecab/src/connector.cpp
+++ b/mecab/src/connector.cpp
@@ -46,7 +46,11 @@ void Connector::close() {
}
bool Connector::openText(const char *filename) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
if (!ifs) {
WHAT << "no such file or directory: " << filename;
return false;
@@ -62,21 +66,35 @@ bool Connector::openText(const char *filename) {
}
bool Connector::compile(const char *ifile, const char *ofile) {
- std::ifstream ifs(WPATH(ifile));
std::istringstream iss(MATRIX_DEF_DEFAULT);
- std::istream *is = &ifs;
+#ifdef HAVE_BOOST
+ boost::filesystem::path path(WPATH(ifile));
+ boost::filesystem::ifstream ifs(path);
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter;
- if (!ifs) {
+ if (!ifs.is_open()) {
std::cerr << ifile
<< " is not found. minimum setting is used." << std::endl;
- is = &iss;
+ filter.push(iss);
+ } else {
+ filter.push(ifs);
}
+ std::istream is(&filter);
+#else
+ std::ifstream ifs(WPATH(ifile));
+ std::istream &is = ifs;
+ if (!ifs) {
+ std::cerr << ifile
+ << " is not found. minimum setting is used." << std::endl;
+ is = iss;
+ }
+#endif
char *column[4];
scoped_fixed_array<char, BUF_SIZE> buf;
- is->getline(buf.get(), buf.size());
+ is.getline(buf.get(), buf.size());
CHECK_DIE(tokenize2(buf.get(), "\t ", column, 2) == 2)
<< "format error: " << buf.get();
@@ -89,7 +107,7 @@ bool Connector::compile(const char *ifile, const char *ofile) {
std::cout << "reading " << ifile << " ... "
<< lsize << "x" << rsize << std::endl;
- while (is->getline(buf.get(), buf.size())) {
+ while (is.getline(buf.get(), buf.size())) {
CHECK_DIE(tokenize2(buf.get(), "\t ", column, 3) == 3)
<< "format error: " << buf.get();
const size_t l = std::atoi(column[0]);
@@ -100,7 +118,12 @@ bool Connector::compile(const char *ifile, const char *ofile) {
matrix[(l + lsize * r)] = static_cast<short>(c);
}
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(ofile),
+ std::ios::binary|std::ios::out);
+#else
std::ofstream ofs(WPATH(ofile), std::ios::binary|std::ios::out);
+#endif
CHECK_DIE(ofs) << "permission denied: " << ofile;
ofs.write(reinterpret_cast<const char*>(&lsize), sizeof(unsigned short));
ofs.write(reinterpret_cast<const char*>(&rsize), sizeof(unsigned short));
diff --git a/mecab/src/context_id.cpp b/mecab/src/context_id.cpp
index c3d6a49..dfa0f5e 100644
--- a/mecab/src/context_id.cpp
+++ b/mecab/src/context_id.cpp
@@ -15,7 +15,11 @@ using namespace MeCab;
bool open_map(const char *filename,
std::map<std::string, int> *cmap,
Iconv *iconv) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << filename;
cmap->clear();
char *col[2];
@@ -46,7 +50,11 @@ bool build(std::map<std::string, int> *cmap,
bool save(const char* filename,
std::map<std::string, int> *cmap) {
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(filename));
+#else
std::ofstream ofs(WPATH(filename));
+#endif
CHECK_DIE(ofs) << "permission denied: " << filename;
for (std::map<std::string, int>::const_iterator it = cmap->begin();
it != cmap->end(); ++it) {
diff --git a/mecab/src/dictionary.cpp b/mecab/src/dictionary.cpp
index f171dd4..afcac54 100644
--- a/mecab/src/dictionary.cpp
+++ b/mecab/src/dictionary.cpp
@@ -192,7 +192,11 @@ bool Dictionary::assignUserDictionaryCosts(
CHECK_DIE(ofs) << "permission denied: " << output;
for (size_t i = 0; i < dics.size(); ++i) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(dics[i].c_str()));
+#else
std::ifstream ifs(WPATH(dics[i].c_str()));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << dics[i];
std::cout << "reading " << dics[i] << " ... ";
scoped_fixed_array<char, BUF_SIZE> line;
@@ -293,7 +297,11 @@ bool Dictionary::compile(const Param &param,
std::istringstream iss(UNK_DEF_DEFAULT);
for (size_t i = 0; i < dics.size(); ++i) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(dics[i].c_str()));
+#else
std::ifstream ifs(WPATH(dics[i].c_str()));
+#endif
std::istream *is = &ifs;
if (!ifs) {
if (type == MECAB_UNK_DIC) {
@@ -495,7 +503,11 @@ bool Dictionary::compile(const Param &param,
std::fill(charset, charset + sizeof(charset), '\0');
std::strncpy(charset, to.c_str(), 31);
+#ifdef HAVE_BOOST
+ iostreams_ofstream bofs(WPATH(output), std::ios::binary|std::ios::out);
+#else
std::ofstream bofs(WPATH(output), std::ios::binary|std::ios::out);
+#endif
CHECK_DIE(bofs) << "permission denied: " << output;
unsigned int magic = 0;
diff --git a/mecab/src/dictionary_generator.cpp b/mecab/src/dictionary_generator.cpp
index fdbbf26..35dfeaa 100644
--- a/mecab/src/dictionary_generator.cpp
+++ b/mecab/src/dictionary_generator.cpp
@@ -25,7 +25,11 @@ void copy(const char *src, const char *dst) {
std::cout << "copying " << src << " to " << dst << std::endl;
Mmap<char> mmap;
CHECK_DIE(mmap.open(src)) << mmap.what();
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(dst), std::ios::binary|std::ios::out);
+#else
std::ofstream ofs(WPATH(dst), std::ios::binary|std::ios::out);
+#endif
CHECK_DIE(ofs) << "permission denied: " << dst;
ofs.write(reinterpret_cast<char*>(mmap.begin()), mmap.size());
ofs.close();
@@ -44,7 +48,11 @@ class DictionaryGenerator {
static void gencid(const char *filename,
DictionaryRewriter *rewrite,
ContextID *cid) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << filename;
scoped_fixed_array<char, BUF_SIZE> line;
std::cout << "reading " << filename << " ... " << std::flush;
@@ -67,7 +75,11 @@ class DictionaryGenerator {
const ContextID &cid,
DecoderFeatureIndex *fi,
int factor) {
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(filename));
+#else
std::ofstream ofs(WPATH(filename));
+#endif
CHECK_DIE(ofs) << "permission denied: " << filename;
LearnerPath path;
@@ -115,10 +127,18 @@ class DictionaryGenerator {
DecoderFeatureIndex *fi,
bool unk,
int factor) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(ifile));
+#else
std::ifstream ifs(WPATH(ifile));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << ifile;
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(ofile));
+#else
std::ofstream ofs(WPATH(ofile));
+#endif
CHECK_DIE(ofs) << "permission denied: " << ofile;
std::cout << "emitting " << ofile << " ... " << std::flush;
diff --git a/mecab/src/dictionary_rewriter.cpp b/mecab/src/dictionary_rewriter.cpp
index 583b089..3bb397c 100644
--- a/mecab/src/dictionary_rewriter.cpp
+++ b/mecab/src/dictionary_rewriter.cpp
@@ -132,7 +132,11 @@ void DictionaryRewriter::clear() { cache_.clear(); }
bool DictionaryRewriter::open(const char *filename,
Iconv *iconv) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << filename;
int append_to = 0;
std::string line;
@@ -201,7 +205,11 @@ bool DictionaryRewriter::rewrite2(const std::string &feature,
bool POSIDGenerator::open(const char *filename,
Iconv *iconv) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
if (!ifs) {
std::cerr << filename
<< " is not found. minimum setting is used" << std::endl;
diff --git a/mecab/src/eval.cpp b/mecab/src/eval.cpp
index 3e2f9bd..dd15c95 100644
--- a/mecab/src/eval.cpp
+++ b/mecab/src/eval.cpp
@@ -123,8 +123,13 @@ class Eval {
const std::string level_str = param.get<std::string>("level");
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs1(WPATH(files[0].c_str()));
+ iostreams_ifstream ifs2(WPATH(files[1].c_str()));
+#else
std::ifstream ifs1(WPATH(files[0].c_str()));
std::ifstream ifs2(WPATH(files[1].c_str()));
+#endif
CHECK_DIE(ifs1) << "no such file or directory: " << files[0].c_str();
CHECK_DIE(ifs2) << "no such file or directory: " << files[0].c_str();
diff --git a/mecab/src/feature_index.cpp b/mecab/src/feature_index.cpp
index 051bdf8..062ef3a 100644
--- a/mecab/src/feature_index.cpp
+++ b/mecab/src/feature_index.cpp
@@ -77,7 +77,11 @@ void FeatureIndex::set_alpha(const double *alpha) {
bool FeatureIndex::openTemplate(const Param &param) {
std::string filename = create_filename(param.get<std::string>("dicdir"),
FEATURE_FILE);
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename.c_str()));
+#else
std::ifstream ifs(WPATH(filename.c_str()));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << filename;
scoped_fixed_array<char, BUF_SIZE> buf;
@@ -529,7 +533,11 @@ bool FeatureIndex::compile(const Param &param,
const char* txtfile, const char *binfile) {
std::string buf;
FeatureIndex::convert(param, txtfile, &buf);
+#ifdef HAVE_BOOST
+ iostreams_ofstream ofs(WPATH(binfile), std::ios::binary|std::ios::out);
+#else
std::ofstream ofs(WPATH(binfile), std::ios::binary|std::ios::out);
+#endif
CHECK_DIE(ofs) << "permission denied: " << binfile;
ofs.write(buf.data(), buf.size());
return true;
@@ -537,7 +545,11 @@ bool FeatureIndex::compile(const Param &param,
bool FeatureIndex::convert(const Param &param,
const char* txtfile, std::string *output) {
+#ifdef HAVE_FILESYSTEM
+ iostreams_ifstream ifs(WPATH(txtfile));
+#else
std::ifstream ifs(WPATH(txtfile));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << txtfile;
scoped_fixed_array<char, BUF_SIZE> buf;
char *column[4];
@@ -618,7 +630,11 @@ bool EncoderFeatureIndex::reopen(const char *filename,
std::vector<double> *alpha,
Param *param) {
close();
+#ifdef HAVE_FILESYSTEM
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
if (!ifs) {
return false;
}
@@ -669,7 +685,11 @@ bool EncoderFeatureIndex::save(const char *filename, const char *header) const {
CHECK_DIE(header);
CHECK_DIE(alpha_);
+#ifdef HAVE_FILESYSTEM
+ iostreams_ofstream ofs(WPATH(filename));
+#else
std::ofstream ofs(WPATH(filename));
+#endif
if (!ofs) {
return false;
}
diff --git a/mecab/src/learner.cpp b/mecab/src/learner.cpp
index 187640c..2d5488a 100644
--- a/mecab/src/learner.cpp
+++ b/mecab/src/learner.cpp
@@ -108,7 +108,11 @@ class CRFLearner {
std::cout << "reading corpus ..." << std::flush;
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(ifile.c_str()));
+#else
std::ifstream ifs(WPATH(ifile.c_str()));
+#endif
CHECK_DIE(ifs) << "no such file or directory: " << ifile;
while (ifs) {
diff --git a/mecab/src/param.cpp b/mecab/src/param.cpp
index 65328a2..b46ac2b 100644
--- a/mecab/src/param.cpp
+++ b/mecab/src/param.cpp
@@ -64,7 +64,11 @@ void Param::dump_config(std::ostream *os) const {
}
bool Param::load(const char *filename) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
CHECK_FALSE(ifs) << "no such file or directory: " << filename;
diff --git a/mecab/src/stream_wrapper.h b/mecab/src/stream_wrapper.h
index b2b9666..a64729a 100644
--- a/mecab/src/stream_wrapper.h
+++ b/mecab/src/stream_wrapper.h
@@ -15,6 +15,10 @@ namespace MeCab {
class istream_wrapper {
private:
+#ifdef HAVE_BOOST
+ boost::iostreams::filtering_streambuf<boost::iostreams::input> filter;
+ boost::filesystem::ifstream* ifs_;
+#endif
std::istream* is_;
public:
std::istream &operator*() const { return *is_; }
@@ -23,17 +27,30 @@ class istream_wrapper {
if (std::strcmp(filename, "-") == 0) {
is_ = &std::cin;
} else {
+#ifdef HAVE_BOOST
+ ifs_ = new boost::filesystem::ifstream(boost::filesystem::path(WPATH(filename)));
+ filter.push(*ifs_);
+ is_ = new std::istream(&filter);
+#else
is_ = new std::ifstream(WPATH(filename));
+#endif
}
}
virtual ~istream_wrapper() {
if (is_ != &std::cin) delete is_;
+#ifdef HAVE_BOOST
+ delete ifs_;
+#endif
}
};
class ostream_wrapper {
private:
+#ifdef HAVE_BOOST
+ boost::iostreams::filtering_streambuf<boost::iostreams::output> filter;
+ boost::filesystem::ofstream* ofs_;
+#endif
std::ostream* os_;
public:
std::ostream &operator*() const { return *os_; }
@@ -42,12 +59,21 @@ class ostream_wrapper {
if (std::strcmp(filename, "-") == 0) {
os_ = &std::cout;
} else {
+#ifdef HAVE_BOOST
+ ofs_ = new boost::filesystem::ofstream(boost::filesystem::path(WPATH(filename)));
+ filter.push(*ofs_);
+ os_ = new std::ostream(&filter);
+#else
os_ = new std::ofstream(WPATH(filename));
+#endif
}
}
virtual ~ostream_wrapper() {
if (os_ != &std::cout) delete os_;
+#ifdef HAVE_BOOST
+ delete ofs_;
+#endif
}
};
}
diff --git a/mecab/src/utils.cpp b/mecab/src/utils.cpp
index fe86657..c2a05c8 100644
--- a/mecab/src/utils.cpp
+++ b/mecab/src/utils.cpp
@@ -298,7 +298,11 @@ bool load_dictionary_resource(Param *param) {
if (homedir) {
const std::string s = MeCab::create_filename(std::string(homedir),
".mecabrc");
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(s.c_str()));
+#else
std::ifstream ifs(WPATH(s.c_str()));
+#endif
if (ifs) {
rcfile = s;
}
@@ -554,7 +558,11 @@ uint64_t fingerprint(const std::string &str) {
}
bool file_exists(const char *filename) {
+#ifdef HAVE_BOOST
+ iostreams_ifstream ifs(WPATH(filename));
+#else
std::ifstream ifs(WPATH(filename));
+#endif
if (!ifs) {
return false;
}
--- a/mecab/src/mecab.h 2017-02-27 21:35:37.334550600 +0900
+++ b/mecab/src/mecab.h 2017-02-27 21:34:40.721553600 +0900
@@ -335,7 +335,7 @@
extern "C" {
#endif
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(__MINGW32__)
#include <windows.h>
# ifdef DLL_EXPORT
# define MECAB_DLL_EXTERN __declspec(dllexport)
--- a/mecab/config.h 2017-02-27 18:35:41.359937900 +0900
+++ b/mecab/config.h 2017-02-27 18:38:03.081206400 +0900
@@ -4,6 +4,8 @@
/* Define if building universal (internal helper macro) */
/* #undef AC_APPLE_UNIVERSAL_BUILD */
+#define HAVE_BOOST 1
+
/* Define to 1 if you have the <ctype.h> header file. */
#define HAVE_CTYPE_H 1
--- a/mecab/src/Makefile 2017-02-27 18:35:34.119863300 +0900
+++ b/mecab/src/Makefile 2017-02-27 20:44:48.005173500 +0900
@@ -161,7 +161,7 @@
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=none
-CXXFLAGS = -O3 -Wall -municode -DUNICODE -D_UNICODE
+CXXFLAGS = -O3 -Wall -municode -DUNICODE -D_UNICODE -std=c++11
CYGPATH_W = cygpath -w
DEFS = -DHAVE_CONFIG_H
DEPDIR = .deps
@@ -185,7 +185,7 @@
LDFLAGS =
LIBICONV = -liconv
LIBOBJS =
-LIBS = -lpthread -lpthread -lstdc++ -liconv
+LIBS = -lpthread -lpthread -lstdc++ -liconv -lboost_iostreams-mgw63-mt-1_63 -lboost_filesystem-mgw63-mt-1_63 -lboost_system-mgw63-mt-1_63 -LD:/msys64/mingw32/local/lib
LIBTOOL = $(SHELL) $(top_builddir)/libtool
LIPO =
LN_S = cp -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment