2

如何编译多种编程语言并将它们链接在一起?由于每种编程语言最适合某些特定情况,我需要使用每种语言中最好的,那么我该怎么做呢?是否可以将 java 与 c++ 或 c 和 Python 与 C 或 C++ 结合使用?是否可以从 c 或 c++ 调用 java 或 python 函数,反之亦然?

4

2 回答 2

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.

于 2013-08-21T18:24:30.300 回答
0

看看libffi - 尽管我相信这主要针对“解释调用编译”的情况。

于 2013-08-23T08:53:51.827 回答