2

How do I compile Multiple Programming Languages and link them together?Since each Programming language is best for some particular cases I need to use best of each language so how do I do it? Is it possible combine java with c++ or c and Python with C or C++?Is it possible to call a java or python function from c or c++ and vice versa?

Praburaj
  • 613
  • 8
  • 21
  • It's called a [Foreign Function Interface](http://en.wikipedia.org/wiki/Foreign_function_interface). The way it is implemented varies depending on which languages are being used. – Robert Harvey Aug 21 '13 at 18:17

2 Answers2

2
  • For calling C from C++ you don't need anything special, since C++ was designed this way
  • You can call C from Python by using native extensions for this you should use ctypes or swig read more here. And here is example how to call Windows API from Python.
  • There is Java Native Interface for calling native C libraries from Java and vice verse read more here
  • It is also possible to call C++ from C If I remember correctly you need to use "extern C" declaration in your C++ code read here
  • It is possible to call C from JavaScript (for example native node modules)

In fact almost any language has possibility to call C libraries because of amount of C libraries and because those are easy to port from system to system. In fact many complex systems uses script language for so called glue code witch uses C libraries. Any way this is broad topic you should tell more about your problem so that we could help you. If you jest want to test concept I think the Python way is easiest.

Community
  • 1
  • 1
Darius Kucinskas
  • 10,193
  • 12
  • 57
  • 79
0

Take a look at libffi - although I believe that's mostly targetting the "interpreted calling compiled" case.

rjp
  • 1,942
  • 12
  • 14