Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling multiple languages together

Is it possible to compile multiple languages together in order to get the best of the different languages.

like image 991
wantoknow Avatar asked Dec 11 '25 00:12

wantoknow


2 Answers

It's definitely possible to link them together (if suitably programmed) after compiling them separately, if the compilers and linkers are all compatible. For example:

g77 -c one.f
gcc -c two.c
gcc -o together one.o two.o

this compiles a Fortran file, then a C file, then links them together in a single executable named together (assuming they call each other properly;-) using the GCC suite of tools.

Microsoft's .NET is a popular way to use multiple languages together -- C#, F#, IronPython, IronRuby, and so on. Visual Studio will handle the compilations into compatible codes and the joining together in assemblies, but you can also do it "by hand" if you wish.

If by "compiling together" you mean having multiple different languages within the same file, that's also possible but rarer -- for example some C compilers have extensions to let you express "inline" assembly language within the same file.

like image 139
Alex Martelli Avatar answered Dec 13 '25 21:12

Alex Martelli


Yes, it's possible, but a lot depends on the specific languages. For example, calling C functions or C++ classes from Python is done routinely.

like image 44
Mark Ransom Avatar answered Dec 13 '25 21:12

Mark Ransom



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!