How to: Call Julia from C#
This is basic sample that shows how to call Julia code from C#
Step 1:
- Set up the 64 bit solution
- Build / Configuration Manager
- Active solution platform /New X64/ Copy settings from Win32
Step 2:
- Code as below
class Program
{
[DllImport("kernel32.dll")]
public static extern bool SetDllDirectory(string pathName);
[DllImport("libjulia.dll")]
public static extern void jl_init(string julia_home_dir);
[DllImport("libjulia.dll")]
public static extern void jl_eval_string(string str);
static void Main(string[] args)
{
SetDllDirectory(@"C:\Julia-0.5.0-dev\bin\");
jl_init(@"C:\Julia-0.5.0-dev\bin\");
jl_eval_string("print(sqrt(2.0))");
jl_eval_string("println(map(round, [1.2,3.5,1.7]))");
}
}
Output
Note:
libjulia.dll: All the necessary symbols to embed Julia are located in libjulia (location: <Julia base dir>\julia\bin)
More details can be found @ Embedding Julia