Search This Blog

Labels

Friday, December 17, 2010

《扩展和嵌入Python解释器(译稿)》1.5 Compilation and Linkage

1.5 Compilation and Linkage 编译和链接

There are two more things to do before you can use your new extension: compiling and linking it with the Python system. If you use dynamic loading, the details may depend on the style of dynamic loading your system uses; see the chapters about building extension modules (chapter 3) and additional information that pertains only to building on Windows (chapter 4) for more information about this.

在你能使用你的新扩展之前还有两件事要做:用Python系统来编译和链接。如果你使用动态加载的话,细节就可能依赖于你的系统使用的动态加载的类型;更多信息可参见关于扩展模块的章节(第三章)和在Windows 上构建的相关的专门内容。

If you can’t use dynamic loading, or if you want to make your module a permanent part of the Python interpreter, you will have to change the configuration setup and rebuild the interpreter. Luckily, this is very simple on UNIX: just place your file (‘spammodule.c’ for example) in the ‘Modules/’ directory of an unpacked source distribution, add a line to the file ‘Modules/Setup.local’ describing your file:

如果你无法使用动态加载,或者你想使你的模块成为Python 解释器一个固定的部分,你将必须修改安装配置并重建解释器。幸运的是,在UNIX 下这非常简单:只要将你的文件(例如:spammodule.c)放入已解压缩的Modules/ 目录下,然后在Modules/Setup.local 文件中加一行你的文件的描述语句:

spam spammodule.o

and rebuild the interpreter by running makein the toplevel directory. You can also run make in the ‘Modules/’ subdirectory, but then you must first rebuild ‘Makefile’ there by running ‘make Makefile’. (This is necessary each time you change the ‘Setup’ file.)

并在顶层目录运行make重建解释器。你也可以在‘Modules/’子目录下运行make命令,但你首先必须通过运行‘makeMakefile’来重建‘Makefile’。(每次你修改‘Setup’文件,这都是必须的)

If your module requires additional libraries to link with, these can be listed on the line in the configuration file as well, for instance:

如果你的模块需要链接另外的库,这些库也能配置文件的那一行中,例如:

spam spammodule.o -lX11

No comments:

Post a Comment