I need to develop an interface to use an existing Julia project from within a C porgram.
As I am VERY newbie in Julia, I started creating a VERY simple Julia script to better understand the operation mode.
The steps I need to achieve are (I guess) :
Write a simple julia script
Create an object (using output-o compilation option)
Create a shared object (by gcc -share)
Create a .h header to use this library from C
Use the Julia library from C
But I am experiencing problems with the last step I just don’t know (and don’t find in Julia doc) how to write the .h file compatible with julia-native library. Thus, when I try to compile my C program I obtain “undefined reference” to my julia function.
Here’s my julia script “MULT.ji” :
module MULT
export doubler
function doubler(x)
x*2
end
function tripler(x)
x*3
end
function quadrupler(x)
x*4
end
end
Here’s my header “mult.h” :
int doubler(int x);
int tripler(int x);
int quadrupler(int x);
Here’s my C file “intcjulia.c”
#include "mult.h"
#include <stdio.h>
int main(){
printf("double de 2 : %u ", doubler(2));
}
Thank you for your response Philip, but I don’t really understand. You mean that the name mangling (such as Upper or lower case or underscores) is incorrect ?
Which is the correct way ?
In you opinion, my .H file, and mainly my .C file are correct ?
Is it the right way to make julia code visible ?
Thanks
If it is feasible to compile/refactor your C program as a library, it is much easier to call C from Julia (or any other high level language) than the other way around.
Thank you for your response stev, but i my case, the existing pattern it is not possible to invert dependencies. It is the existing C program that needs to call functions of the existing Julia module.