According to the ccall doc, it is possible to pass Julia functions to native C functions. But how should I program my Julia function, when the C function need an input function with void return type and take a pointer as an argument?
The “test” function needs an argument function (*f). In C, I made a “myFun” function as input. If I want to use the “test” function in Julia, how should I make a Julia version of “myFun”?
Yes, but you might need to be careful with this if this is in the global namespace of the module, which may get precompiled. In that case you might need to store a constant Ref and perform the handle acquisition in __init__().
The main purpose of the following code is to work around issues of where to load dynamic libraries. In this case, I’m trying to load the dynamic libraries from the current directory while bypassing system configuration issues.
Hi Mark, thanks so much for your reply! It perfectly answered my question. The real project I want to do is using dumka3.c ODE solver in Julia, and define RHS of the ODEs as Julia functions. Do you think it is a good idea to make a Julia wrapper around the C code? Or, may be directly “translate” the C code to a Julia version is better?
dumka is a less stable ROCK with no recurrence relation. Even if that method existed in Julia (which we can add of course), I would still probably recommend ROCK2 or ROCK4 based on the theoretical properties of the method. I don’t think Assyr ever got around to doing a full benchmark between the two (RIP), but I haven’t read anything that would make me prefer dumka to ROCK.
Hi Chris, thanks for recommending ROCK, I will definitely try these methods. Also, I will try to wrap dumka to the common Julia ODE interface, I appreciate any hint on how to make a good wrapper.