Closed rveltz closed 7 years ago
OK, I think I got it to run with
jlcxx::Module& ddesolver_mod = registry.create_module("DDESolver");
ddesolver_mod.add_type<ddesolver::DDE>("DDE")
.constructor<int>()
.constructor<ddesolver::history_f,ddesolver::history_tau,int,int>()
.method("solve", &ProblemBase::Solve);
Not sure it is good to remove the type from the second line. This produces the error for which I have no clue since d
is not in my code.
ERROR: LoadError: Type d has no Julia wrapper
Stacktrace:
[1] DDE(::CxxWrap.SafeCFunction, ::CxxWrap.SafeCFunction, ::Int32, ::Int32) at ./<missing>:0
[2] include_from_node1(::String) at ./loading.jl:569
[3] include(::String) at ./sysimg.jl:14
[4] process_options(::Base.JLOptions) at ./client.jl:305
[5] _start() at ./client.jl:371
while loading /Users/rveltz/work/prog/ddeArndt/wrap-dde.jl, in expression starting on line 29
The julia code leading to this is:
using CxxWrap
@show pwd()
wrap_modules(joinpath(pwd()*"/lib/","libarndtWrap"))
using DDESolver
prob1 = DDESolver.DDE(1)
# typedef int (*history_f) (double * const , const double , const double * const , double * );
# typedef int (*history_tau) (double *, double);
# MacKeyGlass
Nd = 1
N = 1
function tau(tau_a,t)
tau_a[1] = 20.0
return Int32(1)
end
function rhs(Dy, x, y, z)
lambda = 0.2
g = 0.1
am = 1.0
np = 10
Dy[1] = -g*y[1] + lambda*am*z[1]/(am+z[1]*z[1]);
return Int32(0)
end
prob = DDESolver.DDE(safe_cfunction(rhs,Int32,(Ptr{Float64},Float64,Ptr{Float64},Ptr{Float64},)),
safe_cfunction(tau,Int32,(Ptr{Float64},Float64,)),
Int32(1),Int32(1))
Hi,
For the first problem, you need to wrap ProblemBase
before using it as a base type, i.e. first do:
ddesolver_mod.add_type<ProblemBase>("ProblemBase");
Type d
is double (this can be found using the c++filt -t d
shell command, the names are mangled and there is no general way to unmangle them to print a nicer error message). Not sure why it gives that error though, double
is of course supported. Is there a non-const reference to double
somewhere?
Thank you!
It seems there are difficulties to wrap const definitions with safe_cfunction
. In particular the const double * const z
in the type history_f
seems to be the cause of the error. I am not sure what to do for this.
OK, the const pointer problem was a bug, should be fixed on latest master. To prevent unintentional modification of const data, I mapped it to a CxxWrap.ConstPtr
, see the test code here on how to get an array out of it:
https://github.com/JuliaInterop/CxxWrap.jl/blob/master/test/functions.jl#L83-L89
Thank you!!
It works :)
I have a basic wrapper now!!!
Dear author,
I would like you to give me a little push concerning wrapping the following class. I posted a question on discourse about it and you responded to it. However, I can't manage to even get the constructor working despite copying your code on inheritance.
Loading the module with
wrap_modules
leads toCan you please give me hint on how to proceed please?
Thank you for your help,
Best regards