在 Anaconda 中构建 Boost Extension with distutils 和 Microsoft Vi
Build Boost Extension with distutils and Microsoft Visual Studio in Anaconda
我尝试在我的 anaconda 安装(版本 5)(使用虚拟环境)中使用带有distutils
的 boost 库构建扩展。代码是来自James Gregson的MWE。
我setup.py
是
from distutils.core import setup, Extension
import sys, glob, os
# define the name of the extension to use
extension_name = 'ExtensionExample'
extension_version = '1.0'
libdir = r'C:UsersschmmarkAnaconda3envswidy640Librarylib'
# define the directories to search for include files
# to get this to work, you may need to include the path
# to your boost installation. Mine was in
# '/usr/local/include', hence the corresponding entry.
include_dirs = sys.path + [r'C:UsersschmmarkAnaconda3envswidy640Libraryinclude', 'include',
r'C:UsersschmmarkAnaconda3envswidy640include']
# define the library directories to include any extra
# libraries that may be needed. The boost::python
# library for me was located in '/usr/local/lib'
library_dirs = [r'C:UsersschmmarkAnaconda3envswidy640Librarylib']
# define the libraries to link with the boost python library
libraries = ['boost_python37-vc140-mt-x64-1_67']
# define the source files for the extension
source_files = ['src/boost_python_wrapper.cpp', 'src/functions_to_wrap.cpp', 'src/classes_to_wrap.cpp']
# define link arguments
# I change this for testing
# extra_compile_args = ['-DBOOST_ALL_NO_LIB']
# extra_compile_args = ['- -DBOOST_ALL_DYN_LINK']
extra_compile_args = []
# create the extension and add it to the python distribution
setup(name=extension_name, version=extension_version, ext_modules=[
Extension(extension_name, source_files, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries,
extra_compile_args=extra_compile_args)])
使用此配置,对于命令python setup.py build
我收到错误
链接:致命错误LNK1104:无法打开文件"boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc140-mt-x64-1_67.lib"
即使文件boost_python37-vc140-mt-x64-1_67.lib
存在于文件夹 C:UsersschmmarkAnaconda3envswidy640Librarylib
中。
当我设置extra_compile_args = ['-DBOOST_ALL_NO_LIB']
时,错误消失了,但我不想手动导入所有标题。msvc 和 boost 有什么问题?
更新:
在这个答案的帮助下,我改变了boost/python/detail/config.hpp
行
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
自
#define BOOST_LIB_NAME boost_python37
但随后我收到链接错误
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "bool __cdecl are_values_equal(int,int)" (?are_values_equal@@YA_NHH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: int __cdecl wrapped_class::get_value(void)const " (?get_value@wrapped_class@@QEBAHXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: void __cdecl wrapped_class::set_value(int)" (?set_value@wrapped_class@@QEAAXH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(void)" (??0wrapped_class@@QEAA@XZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(int)" (??0wrapped_class@@QEAA@H@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "char const * __cdecl get_string(void)" (?get_string@@YAPEBDXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl num_arguments(bool,bool,bool,bool)" (?num_arguments@@YAH_N000@Z)
buildlib.win-amd64-3.7ExtensionExample.cp37-win_amd64.pyd : fatal error LNK1120: 7 unresolved externals
我想通了这两个错误。
- LNK1104错误
这似乎与使用的加速版本有关。在撰写本文时,boost 库是 anaconda 发行版中的 1.67 版本。使用项目主页上最新的 v1.69 二进制文件时,错误消失了。从项目主页使用 v1.67 时,错误仍然存在。
- LNK2001错误
我提到的例子从詹姆斯格雷格森,cpp 文件仍然是空的。如果您编写实际代码,则可以进行编译,例如用于functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
相关文章:
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 带有 CKKS 的 Microsoft 密封中的矢量点积
- 如何添加预防措施以绕过未注册Microsoft.ACE.OLEDB.12.0?
- 通过Python Distutils(用于Python C扩展)使用可重定位的设备代码编译CUDA代码
- 与其他编译器相比,相同的代码在工作室Microsoft提供不同的输出
- 使用 Outlook 2016 Microsoft Store 连接到 Outlook COM
- 如何在 SEAL 3.1 中使用 CRT 批处理技术Microsoft?
- 使用 CMake,Microsoft MPI 和 Visual Studio 2017 找不到 mpi.h
- 如何在视觉c ++项目中添加箭头键作为修饰键Microsoft
- 为什么Microsoft在新代码中使用结构而不是类?
- Microsoft C++ 用于图形 API 的 Rest SDK
- Microsoft ODBC 无法创建有效的句柄
- 在 Microsoft Access SQL 中调用自定义 DLL 函数时传递的内存地址无效
- 使用IMFSourceReader(Microsoft媒体基金会)进行音频流传输
- C++ VS 错误:<实验/文件系统>提供 std::experimental::文件系统的标头已被Microsoft弃用,将被删除
- 寻求提高Microsoft密封库计算效率的方法
- Microsoft Visual Studio 2019交叉编译CMake库 - 有效,但存在SEG错误
- Microsoft NTLM (v2) 中的时间戳使用
- C++正则表达式失败(GCC vs Microsoft 编译器)
- 在 Anaconda 中构建 Boost Extension with distutils 和 Microsoft Vi