最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【未解决】Python中安装mmseg时编译出错:LINK : error LNK2001: 无法解析的外部符号 initmmseg

Python crifan 7713浏览 0评论

【问题】

想要在当前的:

python 2.7.2

win7 64位

上安装mmseg:

【记录】折腾Python中的mmseg中文分词模块

结果setup.py install时出现error: Unable to find vcvarsall.bat,已经解决了:

【已解决】安装Python模块mmseg出错:error: Unable to find vcvarsall.bat

但是编译过程中却又出现:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>SET VS90COMNTOOLS=%VS100COMNTOOLS%

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>setup.py install
running install
running bdist_egg
running egg_info
writing mmseg.egg-info\PKG-INFO
writing top-level names to mmseg.egg-info\top_level.txt
writing dependency_links to mmseg.egg-info\dependency_links.txt
reading manifest file 'mmseg.egg-info\SOURCES.txt'
writing manifest file 'mmseg.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building 'mmseg' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\mmseg
creating build\temp.win-amd64-2.7\Release\mmseg\mmseg_cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/algor.cpp /Fobuild\temp.win-amd64-2.7\R
elease\mmseg/mmseg_cpp/algor.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
algor.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/algor.cpp(210) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strnc
py_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\vector(537) : warning C4530: 使用了 C++ 异常处理程序,但
未启用展开语义。请指定 /EHsc
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\vector(533): 编译类 模板 成员函数“std::vector<_T
y>::vector(const std::vector<_Ty> &)”时
        with
        [
            _Ty=rmmseg::Word *
        ]
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(167): 参见对正在编译的类 模板 实例化“std
::vector<_Ty>”的引用
        with
        [
            _Ty=rmmseg::Word *
        ]
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(174): 参见对正在编译的类 模板 实例化“std
::_Pair_base<_Ty1,_Ty2>”的引用
        with
        [
            _Ty1=int,
            _Ty2=std::vector<rmmseg::Word *>
        ]
        e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\algor.h(75): 参见对正在编译的类 模板 实例化“std::
pair<_Ty1,_Ty2>”的引用
        with
        [
            _Ty1=int,
            _Ty2=std::vector<rmmseg::Word *>
        ]
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/dict.cpp /Fobuild\temp.win-amd64-2.7\Re
lease\mmseg/mmseg_cpp/dict.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
dict.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/dict.cpp(73) : warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据
mmseg/mmseg_cpp/dict.cpp(178) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(234) : 参见“fopen”的声明
mmseg/mmseg_cpp/dict.cpp(205) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(234) : 参见“fopen”的声明
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/memory.cpp /Fobuild\temp.win-amd64-2.7\
Release\mmseg/mmseg_cpp/memory.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
memory.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/mmseg.cpp /Fobuild\temp.win-amd64-2.7\R
elease\mmseg/mmseg_cpp/mmseg.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
mmseg.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/mmseg.cpp(61) : warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
mmseg/mmseg_cpp/mmseg.cpp(90) : warning C4244: “=”: 从“__int64”转换到“int”,可能丢失数据
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:E:\dev_i
nstall_root\Python27\libs /LIBPATH:E:\dev_install_root\Python27\PCbuild\amd64 /EXPORT:initmmseg build\temp.win-amd64-2.7
\Release\mmseg/mmseg_cpp/algor.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.7\Re
lease\mmseg/mmseg_cpp/memory.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.7
\mmseg.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Rel
ease\mmseg/mmseg_cpp\mmseg.pyd.manifest
LINK : error LNK2001: 无法解析的外部符号 initmmseg
build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib : fatal error LNK1120: 1 个无法解析的外部命令
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe"' failed with exit status 112
0

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>

即,最后出现:

LINK : error LNK2001: 无法解析的外部符号 initmmseg

【解决过程】

1.对应的部分是:

调用

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe

时,传递的参数中包含的:

/EXPORT:initmmseg

此处很明显,找不到函数initmmseg,所以无法无法继续链接。

2.后来搜

python initmmseg

而找到

http://pypm-be.activestate.com/2.6/win64-x64/pool/m/mm/mmseg-1.2.5_win64-x64_2.6_1.pypm.d/log

其中也和我遇到同样问题:

Building on ('Windows', 'apy-win64', '2003Server', '5.2.3790', 'AMD64', 'EM64T Family 6 Model 30 Stepping 5, GenuineIntel') with Python-2.6.4 (r264:75706, Nov  3 2009, 14:24:08) [MSC v.1500 64 bit (AMD64)] at 2010-01-06 23:41:11.822000 (utc)
Extracting REMOTE-LOC\languages\pypm\infinitude.be\data\m\mm\mmseg\mmseg-1.2.2.tar.gz
******** Running build command *******
C:\ActivePython64Python26\Python.exe setup.py install --no-compile --root=_pypm_install_root
[SetupPyBuildFailed] non-zero returncode: 1
command: C:\ActivePython64Python26\Python.exe setup.py install --no-compile --root=_pypm_install_root
pwd: c:\docume~1\apy\locals~1\temp\tmplpxbp0\mmseg-1.2.2
stderr:

stdout:
running install

running build

running build_py
。。。。
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Python26\libs /LIBPATH:C:\Python26\PCbuild\amd64 /EXPORT:initmmseg build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp/algor.obj build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp/memory.obj build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.6\mmseg.pyd /IMPLIB:build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.6\Release\mmseg/mmseg_cpp\mmseg.pyd.manifest

LINK : error LNK2001: unresolved external symbol initmmseg

3.突然想到,会不会是版本的问题。

所以,去换个版本试试。

http://pypi.python.org/pypi/mmseg/1.2.4

下载得到mmseg-1.2.4.tar.gz,解压,打开cmd切换到对应目录,运行

SET VS90COMNTOOLS=%VS100COMNTOOLS%

setup.py install

结果错误依旧,还是:

build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib : fatal error LNK1120: 1 个无法解析的外部命令

4.后来在参考:

http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat

中的:

@Gili: It looks like this problem is due to spaces in the variable, try wrapping it within quotes. For me %VS100COMNTOOLS%="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools" – legends2k Oct 5 ’12 at 11:44

结果自己去我的目录:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools

中看了看,无意间发现了其下有:

vsvars32.bat

打开看了看,内容大概是:

@echo Setting environment for using Microsoft Visual Studio 2010 x86 tools.

@call :GetVSCommonToolsDir
@if "%VS100COMNTOOLS%"=="" goto error_no_VS100COMNTOOLSDIR

@call "%VS100COMNTOOLS%VCVarsQueryRegistry.bat" 32bit No64bit

......
:error_no_Framework35Version
@echo ERROR: Cannot determine the .NET Framework 3.5 version.
@goto end

:end

而且,也去看了看

VS100COMNTOOLS

环境变量,其内容也本身就是:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\

5.至此,貌似环境变量方面都是正常的。

再去随便折腾一下,把:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat

拷贝出来一份,重命名为

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vcvarsall.bat

然后再执行:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

setup.py install

看看结果,结果竟然真的可以了:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.2.4>SET VS90COMNTOOLS=%VS100COMNTOOLS%

E:\Dev_Tools\python\modules\mmseg\mmseg-1.2.4>setup.py install
running install
running bdist_egg
running egg_info
writing mmseg.egg-info\PKG-INFO
writing top-level names to mmseg.egg-info\top_level.txt
writing dependency_links to mmseg.egg-info\dependency_links.txt
reading manifest file 'mmseg.egg-info\SOURCES.txt'
writing manifest file 'mmseg.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\mmseg
creating build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\chars.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\test.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\words.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\__init__.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\search.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\word2.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\_mmseg.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\__init__.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg.pyd -> build\bdist.win-amd64\egg
byte-compiling build\bdist.win-amd64\egg\mmseg\data\test.py to test.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\search.py to search.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\word2.py to word2.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\_mmseg.py to _mmseg.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\__init__.py to __init__.pyc
creating stub loader for mmseg.pyd
byte-compiling build\bdist.win-amd64\egg\mmseg.py to mmseg.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
mmseg._mmseg: module references __file__
creating dist
creating 'dist\mmseg-1.2.4-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing mmseg-1.2.4-py2.7-win-amd64.egg
creating e:\dev_install_root\python27\lib\site-packages\mmseg-1.2.4-py2.7-win-amd64.egg
Extracting mmseg-1.2.4-py2.7-win-amd64.egg to e:\dev_install_root\python27\lib\site-packages
Adding mmseg 1.2.4 to easy-install.pth file

Installed e:\dev_install_root\python27\lib\site-packages\mmseg-1.2.4-py2.7-win-amd64.egg
Processing dependencies for mmseg==1.2.4
Finished processing dependencies for mmseg==1.2.4

E:\Dev_Tools\python\modules\mmseg\mmseg-1.2.4>

6.再去试试1.3.0的版本,是否也可以正常安装。结果也是可以的:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>SET VS90COMNTOOLS=%VS100COMNTOOLS%

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>setup.py install
running install
running bdist_egg
running egg_info
writing mmseg.egg-info\PKG-INFO
writing top-level names to mmseg.egg-info\top_level.txt
writing dependency_links to mmseg.egg-info\dependency_links.txt
reading manifest file 'mmseg.egg-info\SOURCES.txt'
writing manifest file 'mmseg.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\mmseg
creating build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\chars.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\test.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\word2_gen.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\words.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\word_in_word_rm.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\__init__.py -> build\bdist.win-amd64\egg\mmseg\data
creating build\bdist.win-amd64\egg\mmseg\mmseg_cpp
copying build\lib.win-amd64-2.7\mmseg\mmseg_cpp\__init__.py -> build\bdist.win-amd64\egg\mmseg\mmseg_cpp
copying build\lib.win-amd64-2.7\mmseg\search.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\word2.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\_mmseg.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\__init__.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg.pyd -> build\bdist.win-amd64\egg
byte-compiling build\bdist.win-amd64\egg\mmseg\data\test.py to test.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\word2_gen.py to word2_gen.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\word_in_word_rm.py to word_in_word_rm.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\mmseg_cpp\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\search.py to search.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\word2.py to word2.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\_mmseg.py to _mmseg.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\__init__.py to __init__.pyc
creating stub loader for mmseg.pyd
byte-compiling build\bdist.win-amd64\egg\mmseg.py to mmseg.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
mmseg._mmseg: module references __file__
mmseg.data.word2_gen: module references __file__
mmseg.data.word_in_word_rm: module references __file__
creating dist
creating 'dist\mmseg-1.3.0-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing mmseg-1.3.0-py2.7-win-amd64.egg
creating e:\dev_install_root\python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg
Extracting mmseg-1.3.0-py2.7-win-amd64.egg to e:\dev_install_root\python27\lib\site-packages
Removing mmseg 1.2.4 from easy-install.pth file
Adding mmseg 1.3.0 to easy-install.pth file

Installed e:\dev_install_root\python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg
Processing dependencies for mmseg==1.3.0
Finished processing dependencies for mmseg==1.3.0

并且可以看到,上面先是

Removing mmseg 1.2.4 from easy-install.pth file

再去

Adding mmseg 1.3.0 to easy-install.pth file

是可以自动升级的。

7.本以为都正常了,结果,实际上并没有。

因为去运行代码时,又出现

WindowsError: [Error 126]

的错误了,详见:

【未解决】Python中去运行mmseg代码结果出错:WindowsError: [Error 126]

8.所以,还是先要解决此处的链接问题,才能解决后面的代码运行dll导入出错的问题。

9.对于此处的initmmseg,网站能找到的,基本上就唯一一个:

sqlite fts3自定义分词器

不过后来真的找到了相关的:

https://github.com/bearice/python-mmseg/blob/master/mmseg.cpp

中有initmmseg函数的:

PyMODINIT_FUNC
initmmseg(void)
{
    PyObject *m;
    
    m = Py_InitModule("mmseg", Methods);
    if (m == NULL)
        return;
    
    Error = PyErr_NewException("mmseg.error", NULL, NULL);
    Py_INCREF(Error);
    PyModule_AddObject(m, "error", Error);
}

所以,很明显,此处,是有此initmmseg函数的,只是之前编译或链接时,没能很好的整合而导致后面链接时找不到此initmmseg函数。

10.后来也查到了微软的 /EXPORT 的语法:

/EXPORT(导出函数)

所以,此处很明显,就是,在link的时候,会导出initmmseg,但是,在对应的

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\mmseg.cpp

中,也没有找到initmmseg函数,导致刚才网上搜到的那里:

https://github.com/bearice/python-mmseg/blob/master/mmseg.cpp

里面有initmmseg函数。

但是,网上的这个mmseg.cpp比本地的mmseg-1.3.0中的内容少多了。

11.从

https://github.com/bearice/python-mmseg

下载到:

python-mmseg-master.zip

解压后,打开cmd,进入目录,去安装,结果又是其他错误:

E:\Dev_Tools\python\modules\mmseg\python-mmseg-master>SET VS90COMNTOOLS=%VS100COMNTOOLS%

E:\Dev_Tools\python\modules\mmseg\python-mmseg-master>setup.py install
running install
running build
running build_ext
building 'mmseg' extension
creating build
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -I/opt/loca
l/include/mmseg -IE:\dev_install_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg.cpp /Fobuild\temp.win-
amd64-2.7\Release\mmseg.obj
mmseg.cpp
mmseg.cpp : warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\xlocale(323) : warning C4530: 使用了 C++ 异常处理程序,但
未启用展开语义。请指定 /EHsc
mmseg.cpp(4) : fatal error C1083: 无法打开包括文件:“SegmenterManager.h”: No such file or directory
error: command '"c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe"' failed with exit status 2

E:\Dev_Tools\python\modules\mmseg\python-mmseg-master>

12.此处一直想要找到,到底是哪里去设置了参数,去添加了link的参数:

/EXPORT:initmmseg

的,但是一直都没找到。

唯一能看到的是,关于

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0\setup.py

中有对应的文件依赖的说明:

ext_modules=[
    Extension(
    'mmseg',
"""
mmseg/mmseg_cpp/algor.cpp  mmseg/mmseg_cpp/dict.cpp  mmseg/mmseg_cpp/memory.cpp  mmseg/mmseg_cpp/mmseg.cpp
""".split(),
    extra_compile_args=['-O3'],
    depends="""
mmseg/mmseg_cpp/algor.h  mmseg/mmseg_cpp/dict.h    mmseg/mmseg_cpp/rules.h
mmseg/mmseg_cpp/word.h
mmseg/mmseg_cpp/chunk.h  mmseg/mmseg_cpp/memory.h  mmseg/mmseg_cpp/token.h
    """.split(),
    )
],

13.实在逼急了,自己手动去:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\mmseg.cpp

中添加了一个initmmseg的空函数:

    
    DLLEXPORT
    void initmmseg(void)
    {
        
    }

再去重新编译试试,看看效果。

结果导致其他错误了:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:E:\dev_i
nstall_root\Python27\libs /LIBPATH:E:\dev_install_root\Python27\PCbuild\amd64 /EXPORT:initmmseg build\temp.win-amd64-2.7
\Release\mmseg/mmseg_cpp/algor.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.7\Re
lease\mmseg/mmseg_cpp/memory.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.7
\mmseg.pyd /IMPLIB:build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Rel
ease\mmseg/mmseg_cpp\mmseg.pyd.manifest
mmseg.obj : warning LNK4197: 多次指定导出“initmmseg”;使用第一个规范
   正在创建库 build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib 和对象 build\temp.win-amd64-2.7\Release\mmseg/m
mseg_cpp\mmseg.exp
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\mt.exe -nologo -manifest build\temp.win-amd64-2.7\Release\mm
seg/mmseg_cpp\mmseg.pyd.manifest -outputresource:build\lib.win-amd64-2.7\mmseg.pyd;2

build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.pyd.manifest : general error c1010070: Failed to load and parse t
0vnifest. {_~
error: command 'mt.exe' failed with exit status 31

14.之前就猜测,不会是,setup.py的编译过程自己给某个模块添加了initxxx吧

即此处的给mmseg添加了initmmseg。

后来搜了下,参考:

python setup.py build

果然提到这个问题了。

所以,还是去掉手动添加的那个initmmseg。

参考上面中提到的:

http://docs.python.org/2/distutils/setupscript.html#other-options

找到相关的解释了:

2.3.5. Other options

There are still some other options which can be used to handle special cases.

The extra_objects option is a list of object files to be passed to the linker. These files must not have extensions, as the default extension for the compiler is used.

extra_compile_args and extra_link_args can be used to specify additional command line options for the respective compiler and linker command lines.

export_symbols is only useful on Windows. It can contain a list of symbols (functions or variables) to be exported. This option is not needed when building compiled extensions: Distutils will automatically add initmodule to the list of exported symbols.

The depends option is a list of files that the extension depends on (for example header files). The build command will call the compiler on the sources to rebuild extension if any on this files has been modified since the previous build.

15.后来找到这里:

http://bytes.com/topic/python/answers/586093-distutils-ctypes

其也是遇到同样问题:

在linux下编译是OK的,但是windows下编译,生生的多出一个:

LINK : error LNK2001: unresolved external symbol inittest

也是由于distutils会去编译,会自动给“export_symbols ”添加上一个initXXX的函数。导致出错。

16.另外看到:

[Distutils] Patch to MSVCCompiler: ‘export_symbols’

其中提到了msvccompiler.py,找了下,在这里:

E:\dev_install_root\Python27\Lib\distutils

有两个:

msvccompiler.py

msvc9compiler.py

看了看

E:\dev_install_root\Python27\Lib\distutils\msvc9compiler.py

貌似也是上述提交的更新,修改后的版本。

17.手动去把

E:\dev_install_root\Python27\Lib\distutils\msvc9compiler.py

中把对应两行干掉:

          # for sym in (export_symbols or []):
                # export_opts.append("/EXPORT:" + sym)

然后再去编译试试,即取消EXPORT试试,结果还是之前见过的,另外一个问题:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:E:\dev_i
nstall_root\Python27\libs /LIBPATH:E:\dev_install_root\Python27\PCbuild\amd64 build\temp.win-amd64-2.7\Release\mmseg/mms
eg_cpp/algor.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_
cpp/memory.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.7\mmseg.pyd /IMPLIB
:build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\mmseg/mmseg_c
pp\mmseg.pyd.manifest
   正在创建库 build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib 和对象 build\temp.win-amd64-2.7\Release\mmseg/m
mseg_cpp\mmseg.exp
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\mt.exe -nologo -manifest build\temp.win-amd64-2.7\Release\mm
seg/mmseg_cpp\mmseg.pyd.manifest -outputresource:build\lib.win-amd64-2.7\mmseg.pyd;2

build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.pyd.manifest : general error c1010070: Failed to load and parse t
0vnifest. {_~
error: command 'mt.exe' failed with exit status 31

所以,还是还原msvc9compiler.py回来吧。

18.后来终于看懂:

python setup.py build

中的意思了,这人肯定是把

Extention中的

xxx.modulename

写成:

xxx/modulename

了,改为

xxx.modulename

其中xxx是package即可。

但是我此处,不是我写的模块,是别人写的,而且好像也没用到package,所以对于此处问题,还是没有帮助,没法解决。

19.后来又找到一个同样的问题的:

Getting my python c++ extension to compile using Swig and Distutils on Windows

但是没有人回答正确。。

20.又找到一个:

[Distutils] What do I need to run setup.py on Windows?

结果也没有有效的回答。。。

21.手动修改:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0\setup.py

自己添加上:

export_symbols

变成:

ext_modules=[
    Extension(
    'mmseg',
"""
mmseg/mmseg_cpp/algor.cpp  mmseg/mmseg_cpp/dict.cpp  mmseg/mmseg_cpp/memory.cpp  mmseg/mmseg_cpp/mmseg.cpp
""".split(),
    extra_compile_args=['-O3'],
    depends="""
mmseg/mmseg_cpp/algor.h  mmseg/mmseg_cpp/dict.h    mmseg/mmseg_cpp/rules.h
mmseg/mmseg_cpp/word.h
mmseg/mmseg_cpp/chunk.h  mmseg/mmseg_cpp/memory.h  mmseg/mmseg_cpp/token.h
    """.split(),
    export_symbols=[],
    )
],

结果问题依旧。

22.参考了:

http://fuyun.org/2009/12/install-mysql-for-python-on-windows/

再去把:

E:\dev_install_root\Python27\Lib\distutils\msvc9compiler.py

中把export干掉,然后结果是这个:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:E:\dev_i
nstall_root\Python27\libs /LIBPATH:E:\dev_install_root\Python27\PCbuild\amd64 build\temp.win-amd64-2.7\Release\mmseg/mms
eg_cpp/algor.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_
cpp/memory.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.7\mmseg.pyd /IMPLIB
:build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\mmseg/mmseg_c
pp\mmseg.pyd.manifest
   正在创建库 build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib 和对象 build\temp.win-amd64-2.7\Release\mmseg/m
mseg_cpp\mmseg.exp
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\mt.exe -nologo -manifest build\temp.win-amd64-2.7\Release\mm
seg/mmseg_cpp\mmseg.pyd.manifest -outputresource:build\lib.win-amd64-2.7\mmseg.pyd;2

build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.pyd.manifest : general error c1010070: Failed to load and parse t
0vnifest. {_~
error: command 'mt.exe' failed with exit status 31

然后再去

E:\dev_install_root\Python27\Lib\distutils\msvc9compiler.py

中找到:

            ld_args.append(‘/MANIFESTFILE:’ + temp_manifest)

再前后再加一句,变成:

            ld_args.append('/MANIFESTFILE:' + temp_manifest)
            ld_args.append('/MANIFEST')

然后再去编译,最终终于正常编译了:

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>SET VS90COMNTOOLS=%VS100COMNTOOLS%

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>setup.py install
running install
running bdist_egg
running egg_info
writing mmseg.egg-info\PKG-INFO
writing top-level names to mmseg.egg-info\top_level.txt
writing dependency_links to mmseg.egg-info\dependency_links.txt
reading manifest file 'mmseg.egg-info\SOURCES.txt'
writing manifest file 'mmseg.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\mmseg
copying mmseg\search.py -> build\lib.win-amd64-2.7\mmseg
copying mmseg\word2.py -> build\lib.win-amd64-2.7\mmseg
copying mmseg\_mmseg.py -> build\lib.win-amd64-2.7\mmseg
copying mmseg\__init__.py -> build\lib.win-amd64-2.7\mmseg
creating build\lib.win-amd64-2.7\mmseg\data
copying mmseg\data\test.py -> build\lib.win-amd64-2.7\mmseg\data
copying mmseg\data\word2_gen.py -> build\lib.win-amd64-2.7\mmseg\data
copying mmseg\data\word_in_word_rm.py -> build\lib.win-amd64-2.7\mmseg\data
copying mmseg\data\__init__.py -> build\lib.win-amd64-2.7\mmseg\data
creating build\lib.win-amd64-2.7\mmseg\mmseg_cpp
copying mmseg\mmseg_cpp\__init__.py -> build\lib.win-amd64-2.7\mmseg\mmseg_cpp
copying mmseg\data\chars.dic -> build\lib.win-amd64-2.7\mmseg\data
copying mmseg\data\words.dic -> build\lib.win-amd64-2.7\mmseg\data
running build_ext
building 'mmseg' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\mmseg
creating build\temp.win-amd64-2.7\Release\mmseg\mmseg_cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/algor.cpp /Fobuild\temp.win-amd64-2.7\R
elease\mmseg/mmseg_cpp/algor.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
algor.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/algor.cpp(210) : warning C4996: 'strncpy': This function or variable may be unsafe. Consider using strnc
py_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\vector(537) : warning C4530: 使用了 C++ 异常处理程序,但
未启用展开语义。请指定 /EHsc
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\vector(533): 编译类 模板 成员函数“std::vector<_T
y>::vector(const std::vector<_Ty> &)”时
        with
        [
            _Ty=rmmseg::Word *
        ]
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(167): 参见对正在编译的类 模板 实例化“std
::vector<_Ty>”的引用
        with
        [
            _Ty=rmmseg::Word *
        ]
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\utility(174): 参见对正在编译的类 模板 实例化“std
::_Pair_base<_Ty1,_Ty2>”的引用
        with
        [
            _Ty1=int,
            _Ty2=std::vector<rmmseg::Word *>
        ]
        e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\algor.h(75): 参见对正在编译的类 模板 实例化“std::
pair<_Ty1,_Ty2>”的引用
        with
        [
            _Ty1=int,
            _Ty2=std::vector<rmmseg::Word *>
        ]
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/dict.cpp /Fobuild\temp.win-amd64-2.7\Re
lease\mmseg/mmseg_cpp/dict.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
dict.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/dict.cpp(73) : warning C4267: “初始化”: 从“size_t”转换到“int”,可能丢失数据
mmseg/mmseg_cpp/dict.cpp(178) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(234) : 参见“fopen”的声明
mmseg/mmseg_cpp/dict.cpp(205) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s
instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\stdio.h(234) : 参见“fopen”的声明
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/memory.cpp /Fobuild\temp.win-amd64-2.7\
Release\mmseg/mmseg_cpp/memory.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
memory.cpp
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IE:\dev_in
stall_root\Python27\include -IE:\dev_install_root\Python27\PC /Tpmmseg/mmseg_cpp/mmseg.cpp /Fobuild\temp.win-amd64-2.7\R
elease\mmseg/mmseg_cpp/mmseg.obj -O3
cl: 命令行 warning D9002 :忽略未知选项“-O3”
mmseg.cpp
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(31) : warning C4267: “=”: 从“size_t”转换到“int
”,可能丢失数据
e:\dev_tools\python\modules\mmseg\mmseg-1.3.0\mmseg\mmseg_cpp\word.h(38) : warning C4996: 'strncpy': This function or va
riable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online
help for details.
        c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE\string.h(188) : 参见“strncpy”的声明
mmseg/mmseg_cpp/mmseg.cpp(61) : warning C4267: “参数”: 从“size_t”转换到“int”,可能丢失数据
mmseg/mmseg_cpp/mmseg.cpp(90) : warning C4244: “=”: 从“__int64”转换到“int”,可能丢失数据
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\amd64\link.exe /DLL /nologo /INCREMENTAL:NO /LIBPATH:E:\dev_i
nstall_root\Python27\libs /LIBPATH:E:\dev_install_root\Python27\PCbuild\amd64 build\temp.win-amd64-2.7\Release\mmseg/mms
eg_cpp/algor.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/dict.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_
cpp/memory.obj build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp/mmseg.obj /OUT:build\lib.win-amd64-2.7\mmseg.pyd /IMPLIB
:build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib /MANIFESTFILE:build\temp.win-amd64-2.7\Release\mmseg/mmseg_c
pp\mmseg.pyd.manifest /MANIFEST
   正在创建库 build\temp.win-amd64-2.7\Release\mmseg/mmseg_cpp\mmseg.lib 和对象 build\temp.win-amd64-2.7\Release\mmseg/m
mseg_cpp\mmseg.exp
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\x64\mt.exe -nologo -manifest build\temp.win-amd64-2.7\Release\mm
seg/mmseg_cpp\mmseg.pyd.manifest -outputresource:build\lib.win-amd64-2.7\mmseg.pyd;2
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\mmseg
creating build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\chars.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\test.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\word2_gen.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\words.dic -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\word_in_word_rm.py -> build\bdist.win-amd64\egg\mmseg\data
copying build\lib.win-amd64-2.7\mmseg\data\__init__.py -> build\bdist.win-amd64\egg\mmseg\data
creating build\bdist.win-amd64\egg\mmseg\mmseg_cpp
copying build\lib.win-amd64-2.7\mmseg\mmseg_cpp\__init__.py -> build\bdist.win-amd64\egg\mmseg\mmseg_cpp
copying build\lib.win-amd64-2.7\mmseg\search.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\word2.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\_mmseg.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg\__init__.py -> build\bdist.win-amd64\egg\mmseg
copying build\lib.win-amd64-2.7\mmseg.pyd -> build\bdist.win-amd64\egg
byte-compiling build\bdist.win-amd64\egg\mmseg\data\test.py to test.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\word2_gen.py to word2_gen.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\word_in_word_rm.py to word_in_word_rm.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\data\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\mmseg_cpp\__init__.py to __init__.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\search.py to search.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\word2.py to word2.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\_mmseg.py to _mmseg.pyc
byte-compiling build\bdist.win-amd64\egg\mmseg\__init__.py to __init__.pyc
creating stub loader for mmseg.pyd
byte-compiling build\bdist.win-amd64\egg\mmseg.py to mmseg.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying mmseg.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
mmseg._mmseg: module references __file__
mmseg.data.word2_gen: module references __file__
mmseg.data.word_in_word_rm: module references __file__
creating dist
creating 'dist\mmseg-1.3.0-py2.7-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing mmseg-1.3.0-py2.7-win-amd64.egg
removing 'e:\dev_install_root\python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg' (and everything under it)
creating e:\dev_install_root\python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg
Extracting mmseg-1.3.0-py2.7-win-amd64.egg to e:\dev_install_root\python27\lib\site-packages
mmseg 1.3.0 is already the active version in easy-install.pth

Installed e:\dev_install_root\python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg
Processing dependencies for mmseg==1.3.0
Finished processing dependencies for mmseg==1.3.0

E:\Dev_Tools\python\modules\mmseg\mmseg-1.3.0>

23.不过,白高兴一场,因为最后,去测试mmseg,还是同样的错误:

E:\Dev_Root\python\try_mmseg>try_mmseg.py
Traceback (most recent call last):
  File "E:\Dev_Root\python\try_mmseg\try_mmseg.py", line 13, in <module>
    from mmseg import seg_txt;
  File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\__init__
odule>
    import _mmseg as mmseg
  File "E:\dev_install_root\Python27\lib\site-packages\mmseg-1.3.0-py2.7-win-amd64.egg\mmseg\_mmseg.p
dule>
    mmseg = cdll.LoadLibrary(mmseg_lib_path)
  File "E:\dev_install_root\Python27\lib\ctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "E:\dev_install_root\Python27\lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)

即,根本还是无法正常生成动态链接库,无法使用。

只不过,上述编译成lib,导致正常了。。。

 

【总结】

经历千辛万苦,虽然编译成功了,但是结果还是没用的。

因为还是无法正常使用代码。

详见:

【未解决】Python中去运行mmseg代码结果出错:WindowsError: [Error 126]

 

目前,已知的是:

知道了此处的问题,就是由于EXPORT对应的initXXX函数,但是initXXX找不到而导致link时报错;

此处对应的是

http://docs.python.org/2/distutils/setupscript.html#other-options

中解释的:

export_symbols is only useful on Windows. It can contain a list of symbols (functions or variables) to be exported. This option is not needed when building compiled extensions: Distutils will automatically add initmodule to the list of exported symbols.

但是,除了手动去改动

E:\dev_install_root\Python27\Lib\distutils\msvc9compiler.py

把对应的添加EXPORT的代码干掉,其他还真不知道如何取消此export。

但是归根结底,即使编译成功,但是还是无法正常使用此处的mmseg。。。

转载请注明:在路上 » 【未解决】Python中安装mmseg时编译出错:LINK : error LNK2001: 无法解析的外部符号 initmmseg

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (3)

  1. 真是够了!
    jiangjunzhangaa8年前 (2016-10-08)回复
  2. 把你的setup.py脚本中Extension中name的值修改成_mmseg即可解决(注意前面加下划线前缀) 如下: ------------------------------------------------------------------------- ext_modules=[ Extension( '_mmseg', """ mmseg/mmseg_cpp/algor.cpp mmseg/mmseg_cpp/dict.cpp mmseg/mmseg_cpp/memory.cpp mmseg/mmseg_cpp/mmseg.cpp """.split(), extra_compile_args=['-O3'], depends=""" mmseg/mmseg_cpp/algor.h mmseg/mmseg_cpp/dict.h mmseg/mmseg_cpp/rules.h mmseg/mmseg_cpp/word.h mmseg/mmseg_cpp/chunk.h mmseg/mmseg_cpp/memory.h mmseg/mmseg_cpp/token.h """.split(), ) ],
    atolin12年前 (2013-02-04)回复
92 queries in 0.193 seconds, using 22.19MB memory