我在装有Windows 10 Pro的PC上安装了Microsoft Visual Studio Community 2013(版本12.0.31101.00更新4)和Python 3.6.1(v3.6.1:69c0db5,2017年3月21日).
I had Microsoft Visual Studio Community 2013 (Version 12.0.31101.00 Update 4) and Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017) on my PC with Windows 10 Pro.
为了尝试使用Boost.Python的示例,我下载了boost 1.64.0并通过b2使用选项--with-python --toolset=msvc --build-type=complete构建库.结果,我得到了以下文件:
In order to try examples with Boost.Python I downloaded boost 1.64.0 and build libraries by b2 with options --with-python --toolset=msvc --build-type=complete. As a result I have the following files:
- boost_python3-vc120-mt-1_64.dll
- boost_python3-vc120-mt-1_64.lib
- boost_python3-vc120-mt-gd-1_64.dll
- boost_python3-vc120-mt-gd-1_64.lib
- libboost_python3-vc120-mt-1_64.lib
- libboost_python3-vc120-mt-gd-1_64.lib
- libboost_python3-vc120-mt-s-1_64.lib
- libboost_python3-vc120-mt-sgd-1_64.lib
- libboost_python3-vc120-s-1_64.lib
- libboost_python3-vc120-sgd-1_64.lib
- boost_python3-vc120-mt-1_64.dll
- boost_python3-vc120-mt-1_64.lib
- boost_python3-vc120-mt-gd-1_64.dll
- boost_python3-vc120-mt-gd-1_64.lib
- libboost_python3-vc120-mt-1_64.lib
- libboost_python3-vc120-mt-gd-1_64.lib
- libboost_python3-vc120-mt-s-1_64.lib
- libboost_python3-vc120-mt-sgd-1_64.lib
- libboost_python3-vc120-s-1_64.lib
- libboost_python3-vc120-sgd-1_64.lib
然后我在Visual Studio中创建了项目(类型:Win32/DLL),并采用了以下代码此处:
Then I created project (type: Win32 / DLL) in Visual Studio with the following code taken here:
char const* greet() { return "hello, world"; } #include <boost/python.hpp> BOOST_PYTHON_MODULE(hello) { using namespace boost::python; def("greet", greet); }在C/C ++设置的项目属性中,我在Boost和Python的位置(以\ Python36 \ include结尾)中添加了其他包含目录".
In project properties for C/C++ settings I added "Additional Include Directories" to locations of Boost and Python (ends with \Python36\include).
在首次尝试构建项目期间,出现错误:
During the first attempt to build the project an error appears:
错误1错误LNK1104:无法打开文件'python36.lib'
Error 1 error LNK1104: cannot open file 'python36.lib'
因此,在链接器设置其他库目录"的项目属性中,我添加了相应的位置(以\ Python \ Python36 \ libs结尾).之后,我可以继续...进入下一个错误:
So in project properties for Linker settings "Additional Library Directories" I added corresponding location (ends with \Python\Python36\libs). After that I could move on ... to the next error:
错误1错误LNK1104:无法打开文件'boost_python-vc120-mt-gd-1_64.lib'
Error 1 error LNK1104: cannot open file 'boost_python-vc120-mt-gd-1_64.lib'
值得注意的是,我所拥有的文件名与VS2013所查找的文件名的区别只是单词python之后的数字3.
It is noteworthy that the difference in filenames I had and VS2013 looking for is just digit 3 after word python.
在 stackoverflow 和 google组进行了讨论,但没有有价值的提示.唯一有用的信息是库文件名*boost_python-*对应于Python 2,而*boost_python3-*对应于Python 3.
Similar questions at stackoverflow and in google groups are discussed but without valuable tips. The only useful information is that library file names *boost_python-* corresponds to Python 2 and *boost_python3-* to Python 3.
我注意到将构建类型(解决方案配置)从调试"更改为发布"会导致部分库文件名中更改错误消息(现在没有-gd-):
I noticed that changing the build type (Solution Configuration) from Debug to Release leads to change the error message in part of library file name (there is no -gd- now):
错误1错误LNK1104:无法打开文件'boost_python-vc120-mt-1_64.lib'
Error 1 error LNK1104: cannot open file 'boost_python-vc120-mt-1_64.lib'
我想,VS2013知道boost库文件名约定,但可能不知道关于Python 2和Python 3的区别.
I suppose, VS2013 knows boost library file name convention, but probably does not know the difference about Python 2 and Python 3.
所以,我有3个问题:
推荐答案
在社区的帮助下,我找到了一些问题的答案.
With the community help I have found answers to couple of the questions.
库的名称取决于在文件boost/python/detail/config.hpp中定义为宏BOOST_LIB_NAME的值. 我已尝试更改线路(boost 1.64.0中为108)
Name of library depends on value defined as macro BOOST_LIB_NAME in file boost/python/detail/config.hpp. I have tried to change line (108 in boost 1.64.0)
#define BOOST_LIB_NAME boost_python到
#define BOOST_LIB_NAME boost_python3所需的库文件从boost_python-vc120-mt-1_64.lib更改为boost_python3-vc120-mt-1_64.lib.
And desirable library file changed from boost_python-vc120-mt-1_64.lib to boost_python3-vc120-mt-1_64.lib.
应该注意的是,可以在重新定义BOOST_LIB_NAME的情况下创建并使用config.hpp文件auto_link.hpp中的值,而不用更改它们.
It should be noted, that instead of changing values in config.hpp file auto_link.hpp can be created and used with redefinition of BOOST_LIB_NAME.
这也受到定义的约束.
特别是,将代码添加到我的代码的开头(在#include <boost/python.hpp>之前)
In particular, adding to the beginning of my code (before #include <boost/python.hpp>) the line
#define BOOST_PYTHON_STATIC_LIB强制MSVS搜索文件libboost_python3-vc120-mt-1_64.lib(或libboost_python-vc120-mt-1_64.lib),即静态库. 反之亦然
forces MSVS to search file libboost_python3-vc120-mt-1_64.lib (or libboost_python-vc120-mt-1_64.lib), i.e. static lib. And vice versa line
#define BOOST_PYTHON_DYNAMIC_LIB或
#define BOOST_ALL_DYN_LINK可用于从dll导入代码.
can be used to import code from a dll.
更多推荐
配置Visual Studio以与Boost.Python和Python 3配合使用
发布评论