Closed goretkin closed 5 years ago
Actually, I'm not sure exactly what's happening. In the simple MWE below, I see __init__
called exactly once. reset_init!
isn't called. In my larger project, I do see these functions called multiple times. In any case, I expect the test below to pass, but it does not.
MWE at https://github.com/goretkin/CxxInitMWE (archive attached for posterity) CxxInitMWE-master.zip
My difficulties seem to have been related to precompilation and initialization. Adding __precompile__(false)
to my module fixed my issue.
I had done
import Cxx
twice in a project, and due to the linehttps://github.com/JuliaInterop/Cxx.jl/blob/93359f1fe5a837c96047bfb102b70ba358e11d1e/src/Cxx.jl#L178
this resets the active instances. I personally found this behavior surprising, since all the translation units I had previously loaded were loaded into a different instance.
I thought I could keep a handle to the
Cxx.CxxCore.ClangCompiler
instance, so I could use it later. It seems that this definitionhttps://github.com/JuliaInterop/Cxx.jl/blob/93359f1fe5a837c96047bfb102b70ba358e11d1e/src/clanginstances.jl#L40
exists for that use.
So I tried
my_cxx_compiler_instance = Cxx.instance(Cxx.__current_compiler__)
right after all of myaddHeaderDir
andcxxinclude
calls. And then later__current_compiler__ = my_cxx_compiler_instance
However the definitions at https://github.com/JuliaInterop/Cxx.jl/blob/93359f1fe5a837c96047bfb102b70ba358e11d1e/src/codegen.jl#L840-L853 seem to restrict the type of the first argument to be
CxxInstance
unnecessarily.