链接语言 [英] Linking languages

查看:153
本文介绍了链接语言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我先前问了一个问题,了解哪种语言用于AI原型。共识似乎是,如果我想要它的速度,我需要使用一种语言,如Java或C ++,但Python / Perl / Ruby将有利于接口位。

I asked a question earlier about which language to use for an AI prototype. The consensus seemed to be that if I want it to be fast, I need to use a language like Java or C++, but that Python / Perl / Ruby would be good for the interface bits.

因此,这就引出另一个问题。将这些语言链接到一起有多容易?和哪些组合最好?所以,如果我想有一个Ruby CGI类型的程序调用C ++或Java AI函数,是容易做到吗?任何指针,我在哪里寻找关于做这种事情的信息?

So, this leads me on to another question. How easy is it to link these languages together? And which combination works best? So, if I wanted to have a Ruby CGI-type program calling C++ or Java AI functions, is that easy to do? Any pointers for where I look for information on doing that kind of thing? Or would a different combination be better?

我在编写Web应用程序的主要经验是从C ++ CGI开始,然后转移到Java servlet(大约10年前),然后一个长距离的编程我做了一些PHP。但我没有编写一个脚本语言的Web应用程序的经验,然后调用速度关键位的编译语言。欢迎任何建议!

My main experience with writing web applications started with C++ CGI and then moved on to Java servlets (about 10 years ago) and then after a long gap away from programming I did some PHP. But I've not had experience of writing a web application in a scripting language which then calls out to a compiled language for the speed-critical bits. So any advice will be welcome!

推荐答案

Boost.Python 提供了一种将C ++代码转换为Python模块的简单方法。它相当成熟,在我的经验很好。

Boost.Python provides an easy way to turn C++ code into Python modules. It's rather mature and works well in my experience.

例如,不可避免的Hello World ...

For example, the inevitable Hello World...

char const* greet()
{
  return "hello, world";
}

可以通过编写Boost.Python包装器来暴露给Python:

can be exposed to Python by writing a Boost.Python wrapper:

#include <boost/python.hpp>

BOOST_PYTHON_MODULE(hello_ext)
{
  using namespace boost::python;
  def("greet", greet);
}

就是这样。我们完成了。我们现在可以将其构建为共享库。生成的DLL现在对Python是可见的。下面是一个示例Python会话:

That's it. We're done. We can now build this as a shared library. The resulting DLL is now visible to Python. Here's a sample Python session:

>>> import hello_ext
>>> print hello.greet()
hello, world

这篇关于链接语言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆