首页 > 解决方案 > 安装 NLopt - Python - Windows

问题描述

我对编程很陌生,所以我会尽量让自己清楚:

我想安装 NLopt 库 ( https://nlopt.readthedocs.io/en/latest/ ) 以便在学术项目中使用它,但我不断收到错误。

软件包附带的“README-WINDOWS”文件说:

此 .zip 存档包含 DLL 库以及为 Win64 编译的 NLopt 的相关标头 (.h) 和模块定义 (.def) 文件。

为了从 Visual C++ 链接到这个 .dll 文件,您需要为其创建一个 .lib“导入库”,并且可以使用 VC++ 附带的“lib”命令来实现。特别是,运行: lib /def:libnlopt-0.def

要编译 Matlab 插件,请在 matlab 子目录中的文件 nlopt_optimize.c(确保链接到 libnlopt DLL)上使用 Matlab“mex”编译器。

要构建 Python 插件(假设您安装了 Python 和 Numpy),请执行以下操作: python setup.py build_ext --inplace

它们由 MinGW 的 GNU C 编译器编译,具体为:x86_64-w64-mingw32-gcc (GCC) 4.6.3

我设法创建了 .lib 文件,但是当我在 anaconda 提示符下执行“python setup.py build_ext --inplace”命令时,出现以下错误:

(base) C:\Users\Germano\nlopt>python setup.py build_ext --inplace
running build_ext
building '_nlopt' extension
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe /c     /nologo /Ox /W3 /GL /DNDEBUG /MD -I. -IC:\Users\Germano\Anaconda3\lib\site-packages\numpy\core\include -IC:\Users\Germano\Anaconda3\include -IC:\Users\Germano\Anaconda3\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\cppwinrt" /EHsc /Tpnlopt-python.cpp /Fobuild\temp.win-amd64-3.6\Release\nlopt-python.obj
nlopt-python.cpp
c:\users\germano\nlopt\nlopt.hpp(414): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.hpp(443): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.hpp(473): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
c:\users\germano\nlopt\nlopt.hpp(483): warning C4267: 'argument': conversion from 'size_t' to 'unsigned int', possible loss of data
nlopt-python.cpp(5249): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(5256): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(8406): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8411): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8466): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(8467): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(8475): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(8480): warning C4101: '_e': unreferenced local variable
nlopt-python.cpp(9443): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(9444): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(9784): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(9785): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10357): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10358): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10496): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10497): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(10763): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(10764): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(11012): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(11013): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(11493): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(11494): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12060): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12061): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12170): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12171): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12240): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12241): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
nlopt-python.cpp(12367): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data
nlopt-python.cpp(12368): warning C4244: 'initializing': conversion from 'npy_intp' to 'int', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Germano\Anaconda3\libs /LIBPATH:C:\Users\Germano\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.14.26428\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x64" libnlopt-0.lib /EXPORT:PyInit__nlopt build\temp.win-amd64-3.6\Release\nlopt-python.obj /OUT:C:\Users\Germano\nlopt\_nlopt.cp36-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.6\Release\_nlopt.cp36-win_amd64.lib
Creating library build\temp.win-amd64-3.6\Release\_nlopt.cp36-win_amd64.lib and object build\temp.win-amd64-3.6\Release\_nlopt.cp36-win_amd64.exp
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_algorithm
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_remove_equality_constraints
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_lower_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_munge
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_ftol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_population
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_maxtime
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_copy
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_maxtime
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_abs1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_xtol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_stopval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_ftol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_version
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_population
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_ftol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_max_objective
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_initial_step1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_lower_bounds1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_maxeval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_inequality_constraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_local_optimizer
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_inequality_mconstraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_srand
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_dimension
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_force_stop
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_xtol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_algorithm_name
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_maxeval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_default_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_remove_inequality_constraints
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_vector_storage
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_stopval
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_upper_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_rel
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_srand_time
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_upper_bounds1
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_equality_constraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_ftol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_xtol_abs
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_create
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_vector_storage
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_destroy
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_lower_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_upper_bounds
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_initial_step
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_set_min_objective
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_get_force_stop
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_add_equality_mconstraint
nlopt-python.obj : error LNK2001: unresolved external symbol __imp_nlopt_optimize
C:\Users\Germano\nlopt\_nlopt.cp36-win_amd64.pyd : fatal error LNK1120: 51 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.14.26428\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120

(base) C:\Users\Germano\nlopt>

正如我所说,我是编程新手,所以这对我来说没有多大意义。我一直试图在谷歌中寻找它,但没有成功。

标签: pythonwindowsstatic-libraries

解决方案


原来我使用了错误的 Visual C++ 提示符,更改为正确的提示符解决了问题


推荐阅读