Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Same code, worked in Julia Repl's Top Level, but failed inside a module #493

Open
sprhawk opened this issue Sep 17, 2021 · 0 comments
Open

Comments

@sprhawk
Copy link

sprhawk commented Sep 17, 2021

I have code like below:

PREFIX = ENV["PREFIX"]

using Cxx
addHeaderDir(joinpath(PREFIX, "include"))
addHeaderDir("/usr/include")
addHeaderDir("/usr/include/eigen3")

using Libdl
dlopen(joinpath(PREFIX, "lib/AAAA.so"), RTLD_GLOBAL)

cxx"""
#include "BBBB.h"
#include "AAAA.h"

void simulate_cpp() {
    // some C++ code
}
"""

simulate() = @cxx simulate_cpp()

If I put this code in a.jl, then I start julia (1.3.1) with include("a.jl") it will run correctly
If I put this code in one module, defined like below:

module BBB
  # same code as above
end

then when I call this module,

using BBB
# reported warning:
# [ Info: Precompiling BBB [-----]
# WARNING: eval into closed module CxxCore:
# Expr(:let, Expr(:call, :f) = Expr(:block, #= Symbol("/home/xxxx/.julia/packages/Cxx/1RaOv/src/initialization.jl"):72 =#, Expr(:call, :llvmcall, 0x000000000bda98f8, :Cvoid, Expr(:curly, :Tuple))), Expr(:block, #= Symbol("/home/xxxx/.julia/packages/Cxx/1RaOv/src/initialization.jl"):72 =#, Expr(:call, :f)))
#  ** incremental compilation may be fatally broken for this module **

BBB.simulate()
julia> sanyi.simulate()
ERROR: Could not find `simulate_cpp` in translation unit
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] lookup_name(::Cxx.CxxCore.ClangCompiler, ::Tuple{Symbol}, ::Ptr{Nothing}, ::Cxx.CxxCore.CppPtr{Cxx.CxxCore.CxxQualType{Cxx.CxxCore.CppBaseType{Symbol("clang::Decl")},(false, false, false)},(false, false, false)}, ::Bool) at /home/xxx/.julia/packages/Cxx/1RaOv/src/typetranslation.jl:116
 [3] declfornns(::Cxx.CxxCore.ClangCompiler, ::Type{Cxx.CxxCore.CppNNS{Tuple{:simulate_cpp}}}, ::Ptr{Nothing}) at /home/hongbo/.julia/packages/Cxx/1RaOv/src/codegen.jl:273
 [4] declfornns(::Cxx.CxxCore.ClangCompiler, ::Type{Cxx.CxxCore.CppNNS{Tuple{:simulate_cpp}}}) at /home/xxx/.julia/packages/Cxx/1RaOv/src/codegen.jl:240
 [5] _cppcall(::Type, ::Type, ::Bool, ::Bool, ::Tuple{}) at /home/hongbo/.julia/packages/Cxx/1RaOv/src/codegen.jl:559
 [6] #s37#39(::Any, ::Any, ::Any, ::Any) at /home/xxx/.julia/packages/Cxx/1RaOv/src/codegen.jl:841
 [7] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any,N} where N) at ./boot.jl:524
 [8] simulate() at /home/xxx/Developer/Works/BBBB/aaa_demo/aaaa/src/BBB.jl:62
 [9] top-level scope at REPL[2]:1
@sprhawk sprhawk changed the title Same code, worked in Julia Repl, but failed inside a module Same code, worked in Julia Repl's Top Level, but failed inside a module Sep 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant