views:

50

answers:

1

Generally a library will be released in a single language (for example C). If the library tuns out to be useful then many language wrappers for that library will be written. How exactly do they do it?

Kindly someone throw little light on this topic. If it is too language dependent pick language of your choice and explain it.

+4  A: 

There are a few options that come to mind:

  • Port the original C library to the language/platform of your choice
  • Compile the C library into something (like a DLL) that can be invoked from other components
  • Put the library on the web, expose an API over HTTP and wrap that on the client

If I wanted to wrap a C library with a managed (.NET) layer, I'd compile the library into a DLL, exposing the APIs I wanted. Then, I'd use P/Invoke to call those APIs from my C# code.

Jim Lamb
What is the Java domain equivalent of P/Invoke in .NET
claws
What about interpreted languages like perl/python/php?
claws
@claws: JNI is the most common.
Jerry Coffin
@claws: There are two common strategies for Python: Boost::Python and SWIG (which also supports PHP, Perl and Java).
Jerry Coffin
@Jerry Coffin: thanks. I'll try them myself. But, I asked this question from learning point of view. So, could you kindly explain how these SWIG or Boost::Python work to provide wrappers? I want to know about the layer at which these two different languages communicate.
claws
@Jim Lamb: Are these only ways? What other ways do they have?
claws
@claws: SWIG's interface with Python is explained here (to at least some degree): http://www.swig.org/Doc1.3/Python.html.
Jerry Coffin