Outputs of JuliaC compiled functions question

I’ve been experimenting with the new JuliaC functionality for generating small binaries introduced in 1.12. I have been able to successfully compile and run example programs (such as the ones provided in this repo). However, I’ve noticed that in all the examples I’ve seen so far, the ultimate output for these functions is just to print statements to the console and returning the Int 0 to indicate that the program ran successfully. I guess my question is: How do we actually get these functions to return something usable? For example, if another programming language (i.e. Matlab, python, etc) needed to call this binary, how would one set it up to return the result of some calculation?

This is probably a really basic question, but I haven’t been able to find anything specific in the documentation, any specific examples, and my fiddling around with existing examples has just returned errors.

1 Like

The most basic answer is that the binary would read its input from stdin and write its output to stdout, and it’s the callers responsibility to hook those up.

This is a good thread, if you are looking to build a shared library callable from other tools rather than a separate process executable: Creating fully self-contained and pre-compiled library

PackageCompiler may still be your best option, depending on what your code needs at runtime.

Most of the examples are intended for executables that take input text from the terminal and print output text to the terminal before returning the standard status code 0. clib.jl and mylib.jl are intended for shared libraries, and the README explains the latter is intended to be linked to mylibcaller.c. Tutorials on adapting C-compatible inputs and outputs to Julia code are rather lacking so far.

Other languages also generally interface with shared libraries via the C ABI, but they’ll have their own ways of doing it. I haven’t tried it with JuliaC binaries, but I have used Python’s standard library ctypes to roughly wrap shared libraries. There are many other ways for Python to wrap C more properly, but those involve more effort and features.