Tuesday, March 11, 2014

Linking Ada, C and Haskell Together Statically

So, you want to statically link object code from C, Ada and Haskell into one executable? Probably not. But how could that be done, anyway? Many programming languages provide a means both of exporting subroutines to make them callable from C code and importing C functions so they can call them. You can easily find documentation on how to statically link C to one other language. But what if you want link C with two different languages in the same project? Just compile all of the code separately and link the object files, right? Haha. Not so fast! Programming languages have different run-time systems; they have their own libraries and they may use more than just a stack and a heap and a space for global variables. So if you want to include object code from several languages in a single executable, you'll often have to build run-time code for each application and link it in to the executable as well. In this post, I'm going to demonstrate how you can accomplish this in a project that uses C, Ada and Haskell.

Click here.

1 comment:

Scott said...

This is pretty awesome. I was aware of linking C with Java via the JNI (http://docs.oracle.com/javase/7/docs/technotes/guides/jni/) but I've never used that since I don't do desktop application development and the last time I wrote C or C++ was in college! Great article. Thanks for putting it together.