<p>在下文中,pif表示Python接口。首先我有一个通用的头文件,名为conv_太平洋水电站,它具有升迁头和C++ STD库头等。然后对于每个boostpython模块,我都有一个格式为string的文件(这里对应于示例模块genocpp)_pif.cpp公司,其中string大致对应于模块的名称。在</p>
<pre><code>****************************************************************************************
geno_pif.cpp
****************************************************************************************
#include "conv_pif.hpp"
#include <boost/python.hpp>
#include "geno.hpp"
void export_cppvec_conv();
void export_geno()
{
boost::python::def("write_geno_table_affy6_to_file", write_geno_table_affy6_to_file);
}
BOOST_PYTHON_MODULE(genocpp)
{
export_geno();
export_cppvec_conv();
}
*****************************************************************************************
</code></pre>
<P>函数ExpPurtCppvECKCONV对应于(模板化)转换器到/从C++向量到Python列表。我在cppvec_conv文件中有实际的转换器_pif.cpp公司. 特别是,这定义了export_cppvec_conv,它使用模板实例化,所以我可以不用在geno中包含它就可以离开了_pif.cpp公司. 为了说明,export_cppvec_conv的内容如下,其中cppvec_to_python_list和cppvec_from_python_list定义在cppvec_conv的主体中_pif.cpp公司. 在</p>
^{pr2}$
<p>可以根据需要为genocpp模块添加任意数量的转换器。
当然,我已经得到了geno函数的标题吉诺水电站.
最后,我有一个Scons文件,它将所有内容链接在一起</p>
<pre><code>******************************************
Sconstruct
******************************************
#!/usr/bin/python
import commands, glob, os
# Common file, for both executables and Python Interface
common_files = """geno print"""
def pyversion():
pystr = commands.getoutput('python -V')
version = pystr.split(' ')[1]
major, minor = version.split('.')[:2]
return major + '.' + minor
common_base = Split(common_files)
common = [f + ".cpp" for f in common_base]
# For Python interface only
pif_conv = Split("cppvec_conv cppmap_conv cppset_conv")
pif_conv_files = [t+"_pif.cpp" for t in pif_conv]
pif = Split("geno")
pif_files = [t+"_pif.cpp" for t in pif]
# Boost Python Environment
boost_python_env = Environment(
CPPPATH=["/usr/include/python"+pyversion(), "."],
CXXFLAGS='-ftemplate-depth-100 -fPIC -Wall -Werror -pedantic -pipe -O3 -ffast-math -march=opteron',
#CXXFLAGS='-ftemplate-depth-100 -fPIC -Wall -pedantic -O0 -g',
CPPDEFINES=['BOOST_PYTHON_DYNAMIC_LIB'],
LIBPATH=["/usr/lib/python"+pyversion()+"/config"],
LIBS=["python"+pyversion(), "m", "boost_python"],
SHLIBPREFIX="", #gets rid of lib prefix
SHOBJSUFFIX = ".bpo"
)
boost_python_env.SharedLibrary(target='genocpp', source = common + pif_conv_files + pif_files)
</code></pre>
<p>在本例中,只有一个模块,所以pif_文件只有geno_pif.cpp公司. 否则,我只会选择我想要的模块。嗯,也许在某处上传一个有效的例子是最简单的。如果有人对更多细节感兴趣,我想我可以编辑这个?在</p>
<p>问候你,法希姆</p>