擅长:python、mysql、java
<P>可以轻松地使用自定义C++代码扩展Python脚本Boost.Python,有关详细信息,请访问此网站:<a href="http://www.boost.org/doc/libs/1_50_0/libs/python/doc/" rel="nofollow">http://www.boost.org/doc/libs/1_50_0/libs/python/doc/</a></p>
<p>您可以这样使用它:</p>
<pre><code>char const* greet()
{
return "hello, world";
}
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(hello_ext)
{
using namespace boost::python;
def("greet", greet);
}
</code></pre>
<p>您需要将其编译到一个共享库中。在windows上会得到一个.dll,在Linux上会得到一个.so。这个库将包含必要的代码,以便python可以使用它。使用示例:</p>
^{pr2}$
<p>这里还有一些例子:<a href="http://www.boost.org/doc/libs/1_50_0/libs/python/doc/tutorial/doc/html/index.html" rel="nofollow">http://www.boost.org/doc/libs/1_50_0/libs/python/doc/tutorial/doc/html/index.html</a></p>
<p>使用时Boost.Python如果不使用弱动态链接,请记住将共享对象链接到python。PHP和Java也有类似的东西。在</p>
<p>至于其他语言,我从来没有在Java中使用过自定义共享库,而是在PHP中使用过,使用本机Api很痛苦。我发现使用<a href="http://www.swig.org/" rel="nofollow" title="swig">swig</a>方式更令人愉快。在</p>