How to compile the julia code into c language?

I have my code in julia language, can I generated a C code for it?

no, but keep an eye on:

1 Like

No basically. There was at one point Intel’s Julia2C, but it’s outdated. You can however call Julia code from C.

2 Likes

no, checkout:

1 Like

don’t use Modelica or don’t use Julia

1 Like

does you Julia code use Julia packages? you need to manually translate most likely

Yes, I am using several Julia packages (plus user-defined ones) like SparseArrays, LinearAlgebra, StaticArrays, PlotlyJS, PyPlot, BenchmarkTools, NativeFileDialog, JLD2, CSV, DataFrames, Gtk translating them can be done by this GitHub - JuliaLang/PackageCompiler.jl: Compile your Julia Package?

no, that compiles to executable.

there’s no way to translate, not at this scale (i.e. so many julia packages involved)

Aha, how can I translate my embedded julia packages manually?

Re-implement the functions you used in whatever language supported by the other tool you needed?

I think it will be a pain.

You could write a thin wrapper in C that links libjulia and calls your Julia code.

Can you give me an example or link for doing this?

A quick search led me to this: Calling local Julia package from C - Stack Overflow

2 Likes

I think it’s easier to compile a C-callable interface on the Julia side than to mess around with lots of jl_* functions, for example: I am searching for a C++ code implementing the complex polygamma function - Computational Science Stack Exchange

5 Likes

You said they support Fortran or C, do they mean they support shared library? Or they take Fortran or C code and compile together into their stuff

One doesn’t simply “call a c function”, if by calling you mean like ccall() in Julia, then it’s Fortran or C compiled to a .so shared library, which means you can do the same for Julia, by writing a wrapper as suggested above

2 Likes

I have worked in this today, I found that modelica includes the C function directly into its model, in which the C function is compiled by gcc (embedded in modelica). I am not sure if I can do this for julia also as I could not find that gcc support julia.

Seems pretty limiting if it doesn’t let you link to libraries. That would only let you use C code that is completely self contained, which is not true of most interesting code these days.

Are you sure they don’t allow you to compile things yourself and just provide a shared library to load?

2 Likes

They provide to include a shared library as well. So, I am wondering if I can compile a Julia code to a shared library, so I can include this gendered library such as dll but I am not sure if it will be compatible or not.