8

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.

claws
  • 52,236
  • 58
  • 146
  • 195
  • a related read: http://stackoverflow.com/questions/636841/how-do-multiple-languages-interact-in-one-project – claws Jun 29 '10 at 18:22

1 Answers1

5

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
  • 25,355
  • 6
  • 42
  • 48
  • What is the Java domain equivalent of P/Invoke in .NET – claws Jun 29 '10 at 18:14
  • What about interpreted languages like perl/python/php? – claws Jun 29 '10 at 18:16
  • 2
    @claws: JNI is the most common. – Jerry Coffin Jun 29 '10 at 18:16
  • @claws: There are two common strategies for Python: Boost::Python and SWIG (which also supports PHP, Perl and Java). – Jerry Coffin Jun 29 '10 at 18:19
  • @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 Jun 29 '10 at 18:33
  • @Jim Lamb: Are these only ways? What other ways do they have? – claws Jun 29 '10 at 18:35
  • 1
    @claws: SWIG's interface with Python is explained here (to at least some degree): http://www.swig.org/Doc1.3/Python.html. – Jerry Coffin Jun 29 '10 at 21:19