Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to call C/C++ code from other languages such as Java, PHP, Perl, Python, etc?

Tags:

java

c++

c

perl

What is the best way to call C/C++ from other languages such as Java, Python, Perl, PHP, etc?

like image 923
Jared Avatar asked Nov 08 '08 16:11

Jared


People also ask

What are the advantages of Python over C C++ language?

C++ is a bit complex when it comes to the simplicity of language, and it has more syntax rules as well as program conventions. Python is a friendly language. It has a simple and easy-to-learn syntax. Moreover, its features are easy to use, which allows you to write short and readable code.

Is Python based on C?

The Python interpreter is called “CPython” and it's written in the C programming language. This is the default implementation for Python.

Is C used in Java?

The Java programming language is based on both C and C++. It is a procedural language.

Is C the best programming language?

Hence, it is the best language for those who are new to programming. C programming language uses blocks to separate pieces of code performing different tasks. This helps make programming easier and keeps the code clean. Thus, the code is easy to understand even for those who are starting out.


2 Answers

Use Swig, it allows you to generate code for multiple languages that calls any C/C++ functions. http://www.swig.org/

like image 28
Jared Avatar answered Oct 18 '22 16:10

Jared


From Perl

Inline::C
Inline::CPP
Inline::Java
Inline::Python
Inline::Lua

excerpt from Inline::C-Cookbook:

use Inline C => <<'END_C';

  void greet() {
    printf("Hello, world\n");
  }
END_C

greet;
like image 183
Brad Gilbert Avatar answered Oct 18 '22 18:10

Brad Gilbert