Running build_ext, will yield your error:
export.cpp(7): fatal error C1083: Cannot open include file: 'iconv.h': No such file or directory
That is because Python build system doesn't know what we did (in the libiconv dir). To let it know, pass the:
-I (--include-dirs) - will be translated to [MS.Docs]: /I (Additional include directories)
-L (--library-dirs) - will be translated to [MS.Docs]: /LIBPATH (Additional Libpath)
-l (--libraries) - will be translated to [MS.Docs]: LINK Input Files
flags (python setup.py build_ext --help
will display all of them). For now, don't pass #2. and #3. because we won't get to the link phase (where they are required):
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>"e:\Work\Dev\VEnvs\py36x86_test\Scripts\python.exe" setup.py build_ext -I"../libiconv/include"
running build_ext
building '_simstring' extension
C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -I../libiconv/include -Ic:\Install\x86\Python\Python\3.6\include -Ic:\Install\x86\Python\Python\3.6\include "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\INCLUDE" "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt" /EHsc /Tpexport.cpp /Fobuild\temp.win32-3.6\Release\export.obj
export.cpp
export.cpp(112): warning C4297: 'writer::~writer': function assumed not to throw an exception but does
export.cpp(112): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification
export.cpp(126): warning C4297: 'writer::~writer': function assumed not to throw an exception but does
export.cpp(126): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification
export.cpp(37): error C2664: 'size_t libiconv(libiconv_t,const char **,size_t *,char **,size_t *)': cannot convert argument 2 from 'char **' to 'const char **'
export.cpp(37): note: Conversion loses qualifiers
export.cpp(140): note: see reference to function template instantiation 'bool iconv_convert<std::basic_string<char,std::char_traits<char>,std::allocator<char>>,std::wstring>(libiconv_t,const source_type &,destination_type &)' being compiled
with
[
source_type=std::basic_string<char,std::char_traits<char>,std::allocator<char>>,
destination_type=std::wstring
]
error: command 'C:\\Install\\x86\\Microsoft\\Visual Studio Community\\2015\\VC\\BIN\\cl.exe' failed with exit status 2
Things to do (found out fixing the errors one by one, only export.cpp required changes):
#define ICONV_CONST const
(cl.exe doesn't automatically cast constness)
#define __SIZEOF_WCHAR_T__ 2
(as sizeof(wchar_t)
is 2)
Strip out the code that doesn't compile (that I talked about at the beginning): STL containers with 4 byte chars don't compile on Win, wanted to fix the code, and when Win will support such chars, the code will compile OOTB, but I wasn't able to, so I had to do whatever was done for OSX. As a consequence, #ifdef __APPLE__
should be replaced by #if defined(__APPLE__) || defined(WIN32)
(5 occurrences)
Note that #1. and #2. could (should) be done either by cmdline (-D flag, but I wasn't able to specify a value for a defined flag), or in setup.py (so they are only defined once even if they need to be declared in lots of files), but I didn't spend too much time on it, so I'm replacing them directly in the source code.
Either apply the changes manually, either save:
--- export.cpp.orig 2016-11-30 18:53:32.000000000 +0200
+++ export.cpp 2018-02-14 13:36:31.317953200 +0200
@@ -19,9 +19,18 @@
#endif/*USE_LIBICONV_GNU*/
#ifndef ICONV_CONST
+#if defined (WIN32)
+#define ICONV_CONST const
+#else
#define ICONV_CONST
+#endif
#endif/*ICONV_CONST*/
+#if defined (WIN32)
+#define __SIZEOF_WCHAR_T__ 2
+#endif
+
+
template <class source_type, class destination_type>
bool iconv_convert(iconv_t cd, const source_type& src, destination_type& dst)
{
@@ -269,7 +278,7 @@
iconv_close(bwd);
}
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(WIN32)
#include <cassert>
#endif
@@ -283,7 +292,7 @@
retrieve_thru(dbr, query, this->measure, this->threshold, std::back_inserter(ret));
break;
case 2:
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(WIN32)
#if __SIZEOF_WCHAR_T__ == 2
retrieve_iconv<wchar_t>(dbr, query, UTF16, this->measure, this->threshold, std::back_inserter(ret));
#else
@@ -294,7 +303,7 @@
#endif
break;
case 4:
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(WIN32)
#if __SIZEOF_WCHAR_T__ == 4
retrieve_iconv<wchar_t>(dbr, query, UTF32, this->measure, this->threshold, std::back_inserter(ret));
#else
@@ -317,7 +326,7 @@
std::string qstr = query;
return dbr.check(qstr, translate_measure(this->measure), this->threshold);
} else if (dbr.char_size() == 2) {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(WIN32)
#if __SIZEOF_WCHAR_T__ == 2
std::basic_string<wchar_t> qstr;
#else
@@ -333,7 +342,7 @@
iconv_close(fwd);
return dbr.check(qstr, translate_measure(this->measure), this->threshold);
} else if (dbr.char_size() == 4) {
-#ifdef __APPLE__
+#if defined(__APPLE__) || defined(WIN32)
#if __SIZEOF_WCHAR_T__ == 4
std::basic_string<wchar_t> qstr;
#else
as simstring_win.diff. That is a diff. See [SO]: Run / Debug a Django application's UnitTests from the mouse right click context menu in PyCharm Community Edition? (@CristiFati's answer) (Patching UTRunner section) for how to apply patches on Win (basically, every line that starts with one "+" sign goes in, and every line that starts with one "-" sign goes out).
I also submitted this patch to [GitHub]: Georgetown-IR-Lab/simstring - Support for Win, and it was merged today (180222).
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>"c:\Install\x64\Cygwin\Cygwin\AllVers\bin\patch.exe" -i "../simstring_win.diff"
patching file export.cpp
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>rem Looking at export.cpp content, you'll notice the changes
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>"e:\Work\Dev\VEnvs\py36x86_test\Scripts\python.exe" setup.py build_ext -I"../libiconv/include" -L"../libiconv/lib" -llibiconv
running build_ext
building '_simstring' extension
C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -I../libiconv/include -Ic:\Install\x86\Python\Python\3.6\include -Ic:\Install\x86\Python\Python\3.6\include "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\INCLUDE" "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt" /EHsc /Tpexport.cpp /Fobuild\temp.win32-3.6\Release\export.obj
export.cpp
export.cpp(121): warning C4297: 'writer::~writer': function assumed not to throw an exception but does
export.cpp(121): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification
export.cpp(135): warning C4297: 'writer::~writer': function assumed not to throw an exception but does
export.cpp(135): note: destructor or deallocator has a (possibly implicit) non-throwing exception specification
C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -I../libiconv/include -Ic:\Install\x86\Python\Python\3.6\include -Ic:\Install\x86\Python\Python\3.6\include "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\INCLUDE" "-IC:\Install\x86\Microsoft\Visual Studio Community\2015\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.16299.0\winrt" /EHsc /Tpexport_wrap.cpp /Fobuild\temp.win32-3.6\Release\export_wrap.obj
export_wrap.cpp
C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\BIN\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:c:\Install\x86\Python\Python\3.6\Libs /LIBPATH:../libiconv/lib /LIBPATH:e:\Work\Dev\VEnvs\py36x86_test\libs /LIBPATH:e:\Work\Dev\VEnvs\py36x86_test\PCbuild\win32 "/LIBPATH:C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\LIB" "/LIBPATH:C:\Install\x86\Microsoft\Visual Studio Community\2015\VC\ATLMFC\LIB" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\ucrt\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x86" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.16299.0\um\x86" libiconv.lib /EXPORT:PyInit__simstring build\temp.win32-3.6\Release\export.obj build\temp.win32-3.6\Release\export_wrap.obj /OUT:build\lib.win32-3.6\_simstring.cp36-win32.pyd /IMPLIB:build\temp.win32-3.6\Release\_simstring.cp36-win32.lib
Creating library build\temp.win32-3.6\Release\_simstring.cp36-win32.lib and object build\temp.win32-3.6\Release\_simstring.cp36-win32.exp
Generating code
Finished generating code
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>dir /b "build\lib.win32-3.6"
_simstring.cp36-win32.pyd
Let's try to see if we can use it:
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>"e:\Work\Dev\VEnvs\py36x86_test\Scripts\python.exe" sample.py
Traceback (most recent call last):
File "E:\Work\Dev\StackOverflow\q048528041\simstring-master\simstring.py", line 18, in swig_import_helper
fp, pathname, description = imp.find_module('_simstring', [dirname(__file__)])
File "e:\Work\Dev\VEnvs\py36x86_test\lib\imp.py", line 296, in find_module
raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named '_simstring'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sample.py", line 3, in <module>
import simstring
File "E:\Work\Dev\StackOverflow\q048528041\simstring-master\simstring.py", line 28, in <module>
_simstring = swig_import_helper()
File "E:\Work\Dev\StackOverflow\q048528041\simstring-master\simstring.py", line 20, in swig_import_helper
import _simstring
ModuleNotFoundError: No module named '_simstring'
That is because when importing SimString, which in turn imports _simstring (the .pyd), Python doesn't find it. To fix this:
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>set PYTHONPATH=%PYTHONPATH%;build\lib.win32-3.6
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>set PATH=%PATH%;..\libiconv\bin
(py36x86_test) E:\Work\Dev\StackOverflow\q048528041\simstring-master>"e:\Work\Dev\VEnvs\py36x86_test\Scripts\python.exe" sample.py
('Barack Hussein Obama II',)
('James Gordon Brown',)
()
('Barack Hussein Obama II',)