CxxWrap.jl
CxxWrap.jl copied to clipboard
Calling `wrapmodule` in same module `include(depsfile)` triggers segfault
upon call of any wrapped in wrapmodule
.
I am reproducing this in the xtensor-julia-cookiecutter project here: https://github.com/QuantStack/xtensor-julia-cookiecutter/pull/9
Ran into the same issue. Resolved by including the __init__()
function from the README.
# Load the module and generate the functions
module CppHello
using CxxWrap
@wrapmodule(joinpath("path/to/built/lib","libhello"))
function __init__()
@initcxx
end
end
# Call greet and show the result
@show CppHello.greet()
Yes, that's exactly it, thanks for replying Josh. To expand a bit on this, __init__
is now required because precompilation is on by default in Julia 1.0. Function pointers are stored in an array that is created by @wrapmodule
and filled with up-to-date values by @initcxx
. If you turn off precompilation the version with just @wrapmodule
would also work, but that's not recommended of course.
I have run into something similar in relation to a CxxWrap-based-submodule, say CppHello
in a project, say Foo.jl
:
module Foo
module CppHello
using CxxWrap
@wrapmodule(joinpath("path/to/built/lib","libhello"))
function __init__()
@initcxx
end
end
greet() = CppHello.greet()
export greet
end
A sample like this causes a segmentation fault:
using Foo
greet()
Strangely, this seemed to work
include("src/Foo.jl")
using .Foo
greet()
Disabling precompilation seems to work as well.
Actual code is here: https://github.com/IHPSystems/pylon_julia_wrapper/blob/master/src/wrapper.jl