首先,编译boost_python.dll:
在目录boost/boost_1_32_0/libs/python/build/VisualStudio下,有vc的工程文件boost_python.dsw,我是用VC6编译的,这个文件刚好用:-)打开它。编译release还是debug随便,在tools->option->directories中,添加include file,D:/BOOST/BOOST_1_32_0和C:/TOOLS/PYTHON/INCLUDE(<pyconfig.h>文件路径),添加Library files,C:/TOOLS/PYTHON/LIBS(包涵python24.lib),然后就可以编译通过了,顺利!
接下来,编译教程中的hello.cpp,就是
>>import hello
>>hello.greet()
'Hello, world!'
的那个文件,要使用bjam,boost32里面那个就好用,至于Jamfile用原配的吧
需要注意的是:
set PYTHON_ROOT=c:/dev/tools/python
set PYTHON_VERSION=2.2
这两句话一定要执行一下,尤其PYTHON_VERSION,一定要是2.2,千万别耍小聪明,弄个2.3,2.4什么的,不然自讨苦吃,然后开始编译(使用vc6)
bjam -sTOOLS=msvc
很快就能得到 hello.pyd,表示编译成功!
最后,把 hello.pyd和boost_python.dll拷贝到同一个目录,如:D:/python/boost下,来到命令行运行:
D:/python/boost/python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>import hello
>>hello.greet()
'Hello, world!'
>>
万事大吉。
在目录boost/boost_1_32_0/libs/python/build/VisualStudio下,有vc的工程文件boost_python.dsw,我是用VC6编译的,这个文件刚好用:-)打开它。编译release还是debug随便,在tools->option->directories中,添加include file,D:/BOOST/BOOST_1_32_0和C:/TOOLS/PYTHON/INCLUDE(<pyconfig.h>文件路径),添加Library files,C:/TOOLS/PYTHON/LIBS(包涵python24.lib),然后就可以编译通过了,顺利!
接下来,编译教程中的hello.cpp,就是
>>import hello
>>hello.greet()
'Hello, world!'
的那个文件,要使用bjam,boost32里面那个就好用,至于Jamfile用原配的吧
需要注意的是:
set PYTHON_ROOT=c:/dev/tools/python
set PYTHON_VERSION=2.2
这两句话一定要执行一下,尤其PYTHON_VERSION,一定要是2.2,千万别耍小聪明,弄个2.3,2.4什么的,不然自讨苦吃,然后开始编译(使用vc6)
bjam -sTOOLS=msvc
很快就能得到 hello.pyd,表示编译成功!
最后,把 hello.pyd和boost_python.dll拷贝到同一个目录,如:D:/python/boost下,来到命令行运行:
D:/python/boost/python
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>import hello
>>hello.greet()
'Hello, world!'
>>
万事大吉。
本文介绍了Python与Boost相关的编译及运行过程。先编译boost_python.dll,在VC6中添加include file和Library files路径即可编译通过。接着编译hello.cpp,使用bjam,注意设置PYTHON_ROOT和PYTHON_VERSION。最后将编译得到的文件拷贝到同一目录,在命令行运行测试成功。
928

被折叠的 条评论
为什么被折叠?



