boost python单步调试_Boost.Python构建与测试HOWTO

There is no need to "install Boost" in order to get started usingBoost.Python.  These instructions use Boost.Build projects,which will build those binaries as soon as they're needed.  Yourfirst tests may take a little longer while you wait forBoost.Python to build, but doing things this way will save you fromworrying about build intricacies like which library binaries to usefor a specific compiler configuration and figuring out the rightcompiler options to use yourself.

使用Boost.Python不需要“安装Boost”。这里的教程利用了Boost.Build项目,它会在需要时自动构建那些二进制库。你的第一个测试,可能需要较长的时间,你需要等待Boost.Python的构建,但这样做,让你不必担忧错综复杂的构建,如,某个特定编译器配置该使用哪个二进制库,也让你免于自己设置编译器选项。

Note

Of course it's possible to use other build systems tobuild Boost.Python and its extensions, but they are notofficially supported by Boost.  Moreover 99% of all "I can'tbuild Boost.Python" problems come from trying to use anotherbuild system without first following these instructions.

当然,也可以使用其他的编译系统,来构建Boost.Python及其扩展,但它们不是Boost正式支持的。所有“我无法编译Boost.Python”的问题,99%以上是因为试图使用另一种编译系统,而没有先按这个教程做。

If you want to use another system anyway, we suggest that youfollow these instructions, and then invoke bjam with the

-a -ofilename

options to dump the build commands it executes to a file, soyou can see what your alternate build system needs to do.

如果你想使用另一个系统,我们建议你先遵循这些指示,然后用以下参数调用bjam,

-a -ofilename

来输出它对文件执行的构建命令,这样你就可以看到你的编译系统需要做些什么。

Get Boost; see sections 1 and 2 [Unix/Linux, Windows] of theBoost Getting Started Guide.

获取Boost;见Boost入门指南第1和第2节[Unix/Linux,Windows]。

Get the bjam build driver.  See section 5 [Unix/Linux,Windows] of the Boost Getting Started Guide.

获取bjam构建驱动器。见Boost入门指门第5节[Unix/Linux,Windows]。

cd into the libs/python/example/quickstart/ directory of yourBoost installation, which contains a small example project.

cd到Boost安装目录下的libs/python/example/quickstart/,那里有个小的示例工程。

Invoke bjam.  Replace the "stage" argument from theexample invocation from section 5 of the Getting StartedGuide with "test," to build all the test targets.  Also addthe argument "--verbose-test" to see the output generated bythe tests when they are run.

调用bjam。将入门指南第5节例示的调用命令中的“stage”参数替换为“test”,来构建所有测试目标。  同时添加参数“--verbose-test”来查看测试运行时生成的输出。

On Windows, your bjam invocation might look something like:

在Windows上,你的bjam调用可能像这样:

C:\boost_1_34_0\…\quickstart> bjam toolset=msvc --verbose-test test

and on Unix variants, perhaps,

而在各种Unix上,可能是:

~/boost_1_34_0/…/quickstart$ bjam toolset=gcc --verbose-test test

Note to Windows Users

Windows用户注意

For the sake of concision, the rest of this guide will useunix-style forward slashes in pathnames instead of thebackslashes with which you may be more familiar.  The forwardslashes should work everywhere except in Command Promptwindows, where you should use backslashes.

为求简洁,本指南的其余部分将在路径中使用unix风格的斜杠,而不是你可能更熟悉的反斜杠。斜杠应该到处可用,除了命令提示符窗口,在那里您应该使用反斜杠。

If you followed this procedure successfully, you will have built anextension module called extending and tested it by running aPython script called test_extending.py.  You will also havebuilt and run a simple application called embedding that embedspython.

如果你能成功地遵循这个过程,你将构建出一个扩展模块,名为extending,并运行一个名为test_extending.py的Python脚本测试它。你也将构建并运行一个内嵌python的简单应用程序,名为embedding。

If you're seeing lots of compiler and/or linker error messages,it's probably because Boost.Build is having trouble finding yourPython installation.  You might want to pass the--debug-configuration option to bjam the first few timesyou invoke it, to make sure that Boost.Build is correctly locatingall the parts of your Python installation.  If it isn't, considerConfiguring Boost.Build as detailed below.

如果你见到大量编译或连接的错误信息,那可能是因为Boost.Build无法找到你的Python安装。你也许要在最初几次调用bjam时,传入--debug-configuration参数,以确保Boost.Build正确定位了所有Python组件。 如果不是,请考虑配置Boost.Build。

If you're still having trouble, Someone on one of the followingmailing lists may be able to help:

如果仍有问题,请向以下邮件列表寻求帮助:

The Boost.Build mailing list for issues related to Boost.Build

The Python C++ Sig for issues specifically related to Boost.Python

Boost.Build邮件列表,Boost.Build相关问题

PythonC++ Sig,Boost.Python相关的专门问题

Rejoice!  If you're new to Boost.Python, at this point it might bea good idea to ignore build issues for a while and concentrate onlearning the library by going through the tutorial and perhapssome of the reference documentation, trying out what you'velearned about the API by modifying the quickstart project.

恭喜!如果您是Boost.Python新手,此时,最好暂时不理会构建问题,而是集中精力去学习库,尽快学完教程,然后可能是参考文档,同时通过修改快速入门工程,试用你所学到的API。

If you're content to keep your extension module forever in onesource file called extending.cpp, inside your Boostdistribution, and import it forever as extending, then you canstop here.  However, it's likely that you will want to make a fewchanges.  There are a few things you can do without having to learnBoost.Build in depth.

如果你满足于此,扩展模块的源文件永远是extending.cpp,位于Boost发布目录中,并永远按extending导入,那么你就可以到此为止。 不过很可能是,你会想作一些变动。有许多事你可以做,而无须深入学习Boost.Build。

The project you just built is specified in two files in the currentdirectory: boost-build.jam, which tells bjam where it canfind the interpreted code of the Boost build system, andJamroot, which describes the targets you just built.  Thesefiles are heavily commented, so they should be easy to modify.Take care, however, to preserve whitespace.  Punctuation such as; will not be recognized as intended by bjam if it is notsurrounded by whitespace.

你刚刚构建的工程,是由当前目录下的两个文件详细说明的:boost-build.jam(它告诉bjam,哪里可以找到Boost编译系统的解释代码),和Jamroot(它描述了你刚刚构建的目标)。这些文件具有详细的注释,所以它们应该很容易修改。不过小心,要保留空白字符。如;这样的标点符号,如果周围没有空白字符,bjam将无法识别。

Relocate the Project

工程移位

You'll probably want to copy this project elsewhere so you canchange it without modifying your Boost distribution.  To do that,simply

你可能想把该工程复制到其他位置,这样你就可以修改它,而不必在Boost发布目录中更改。要做到这一点,只需

copy the entire libs/python/example/quickstart/ directoryinto a new directory.

In the new copies of boost-build.jam and Jamroot, locatethe relative path near the top of the file that is clearlymarked by a comment, and edit that path so that it refers to thesame directory your Boost distribution as it referred to whenthe file was in its original location in thelibs/python/example/quickstart/ directory.

复制整个libs/python/example/quickstart/目录到一个新的目录。

在新的boost-build.jam和Jamroot副本中,靠近文件顶部,找到由一条注释清楚标注的相对路径,然后编辑这个路径,让它指向Boost发布目录,与它原来(当文件在libs/python/example/quickstart/目录时)所指目录相同。

For example, if you moved the project from/home/dave/boost_1_34_0/libs/python/example/quickstart to/home/dave/my-project, you could change the first path inboost-build.jam from

例如,如果你的工程从/home/dave/boost_1_34_0/libs/python/example/quickstart移至/home/dave/my-project,你可以更改boost-build.jam中的第一个路径,从

../../../../tools/build/v2

to

改为

/home/dave/boost_1_34_0/tools/build/v2

and change the first path in Jamroot from

并且,将Jamroot中的第一个路径从

../../../..

to

改为

/home/dave/boost_1_34_0

Add New or Change Names of Existing Source Files

添加新的源文件或更改源文件名

The names of additional source files involved in building yourextension module or embedding application can be listed inJamroot right alongside extending.cpp or embedding.cpprespectively.  Just be sure to leave whitespace around eachfilename:

构建扩展模块或内嵌应用程序时,涉及的其他源文件的名字,可以在Jamroot中列出,分别列于extending.cpp或embedding.cpp旁边。只是每个文件名周围,务必留下空白字符:

… file1.cpp file2.cpp file3.cpp …

Naturally, if you want to change the name of a source file you cantell Boost.Build about it by editing the name in Jamroot.

当然,如果你想要更改源文件名,你可以编辑Jamroot中的文件名,来告诉Boost.Build。

Change the Name of your Extension Module

更改扩展模块的名字

The name of the extension module is determined by two things:

扩展模块的名字,由两个地方决定:

the name in Jamroot immediately following python-extension, and

the name passed to BOOST_PYTHON_MODULE in extending.cpp.

在Jamroot中紧跟python-extension的名字,和

在extending.cpp中传给BOOST_PYTHON_MODULE的名字。

To change the name of the extension module from extending tohello, you'd edit Jamroot, changing

要将扩展模块名从extending改为hello,你需要编辑Jamroot,将

python-extension extending : extending.cpp ;

to

改为

python-extension hello : extending.cpp ;

and you'd edit extending.cpp, changing

还需要编辑extending.cpp,将

BOOST_PYTHON_MODULE(extending)

to

改为

BOOST_PYTHON_MODULE(hello)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值