Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Compiler Object Code (Byte Code?)

A typical C program would be compiled, assembled, linked and loaded. I know that Java works with the JVM and produces byte code. Would it be possible to connect both "object files" using the linker? For example, a C program and a C++ program can be used together by playing with the linker and linking both object files.

Can the same be done between C and Java?

like image 577
darksky Avatar asked Dec 05 '25 22:12

darksky


2 Answers

You can't directly link compiled C code with compiled Java code.

You can call compiled C or C++ code from Java using Java Native Interface (JNI):

The Java Native Interface (JNI) enables the integration of code written in the Java programming language with code written in other languages such as C and C++. It allows programmers to take full advantage of the Java platform without having to abandon their investment in legacy code.

like image 131
qbert220 Avatar answered Dec 07 '25 16:12

qbert220


This might be possible if you compile the C code to JVM bytecode, not to native code, so you would 'link' at the JVM level, not via a native object linker.

See http://en.wikipedia.org/wiki/Java_virtual_machine#C_to_bytecode_compilers

like image 22
DNA Avatar answered Dec 07 '25 17:12

DNA



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!