Search code examples
compilation

Compiling multiple languages together and calling function from one language to other


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?


Solution

    • 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.