On my system this bash script
cat << EOF > meson.build
project('CxxWrap', 'cpp',
version : '0.1',
default_options : ['warning_level=3', 'cpp_std=c++17'])
compiler = meson.get_compiler('cpp')
##############################
# CxxWrap dirs
##############################
r = run_command('julia','--project', '-e', 'using CxxWrap; print(CxxWrap.prefix_path())')
assert(r.returncode()==0, 'Cannot get CxxWrap path')
cxxwrap_libdir = r.stdout()+'/lib'
cxxwrap_incdir = r.stdout()+'/include'
lib_cxxwrap = compiler.find_library('cxxwrap_julia', dirs : [cxxwrap_libdir])
##############################
# julia dirs
##############################
r = run_command('julia', '-e', 'print(Sys.BINDIR[1:end-4])')
assert(r.returncode()==0, 'Cannot get Julia lib path')
julia_libdir = r.stdout()+'/lib'
julia_incdir = r.stdout()+'/include/julia'
lib_julia = compiler.find_library('julia',
dirs : [julia_libdir])
lib = shared_library( 'demo', ['libdemo.cpp'],
include_directories: [ cxxwrap_incdir, julia_incdir ],
dependencies: [lib_cxxwrap,lib_julia],
cpp_args : '-DJULIA_ENABLE_THREADING')
EOF
cat << EOF > libdemo.cpp
#include "jlcxx/array.hpp"
#include "jlcxx/module.hpp"
struct Demo {
Demo(){};
jlcxx::Array<int> test() const {
jlcxx::Array<int> jres;
jres.push_back(0);
return jres;
}
};
JLCXX_MODULE define_julia_module(jlcxx::Module &mod) {
mod.add_type<Demo>("Demo").method("test", &Demo::test);
}
EOF
cat << EOF > demo.jl
module M
using CxxWrap
@wrapmodule(() -> joinpath("build/libdemo.so"),:define_julia_module)
export Demo
export test
end
using Main.M
d=Demo()
M.test(d)
EOF
CXX=clang++ meson setup build
cd build
ninja
cd ..
julia demo.jl
produces the following output:
The Meson build system
Version: 0.61.2
Source dir: /home/user/tmp
Build dir: /home/user/tmp/build
Build type: native build
Project name: CxxWrap
Project version: 0.1
C++ compiler for the host machine: clang++ (clang 14.0.0-1ubuntu1 "Ubuntu clang version 14.0.0-1ubuntu1.1")
C++ linker for the host machine: clang++ ld.bfd 2.38
Host machine cpu family: x86_64
Host machine cpu: x86_64
WARNING: You should add the boolean check kwarg to the run_command call.
It currently defaults to false,
but it will default to true in future releases of meson.
See also: https://github.com/mesonbuild/meson/issues/9300
Library cxxwrap_julia found: YES
Library julia found: YES
Build targets in project: 1
Found ninja-1.10.1 at /usr/bin/ninja
[1/2] Compiling C++ object libdemo.so.p/libdemo.cpp.o
In file included from ../libdemo.cpp:2:
/home/user/.julia/artifacts/7b2099c0a944e2b2d7f7ca3254c9681a9bf579a0/include/jlcxx/module.hpp:1205:16: warning: unused variable 'is_abstract' [-Wunused-variable]
const bool is_abstract = jl_is_abstracttype(m_dt);
^
/home/user/.julia/artifacts/7b2099c0a944e2b2d7f7ca3254c9681a9bf579a0/include/jlcxx/module.hpp:753:23: warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
method("copy", [this](const T& other)
^
/home/user/.julia/artifacts/7b2099c0a944e2b2d7f7ca3254c9681a9bf579a0/include/jlcxx/module.hpp:1324:5: note: in instantiation of function template specialization 'jlcxx::Module::add_copy_constructor<Demo>' requested here
add_copy_constructor<T>(base_dt);
^
/home/user/.julia/artifacts/7b2099c0a944e2b2d7f7ca3254c9681a9bf579a0/include/jlcxx/module.hpp:1341:10: note: in instantiation of function template specialization 'jlcxx::Module::add_type_internal<Demo, jlcxx::ParameterList<>, _jl_datatype_t>' requested here
return add_type_internal<T, SuperParametersT>(name, super);
^
../libdemo.cpp:14:7: note: in instantiation of function template specialization 'jlcxx::Module::add_type<Demo, jlcxx::ParameterList<>, _jl_datatype_t>' requested here
mod.add_type<Demo>("Demo").method("test", &Demo::test);
^
2 warnings generated.
[2/2] Linking target libdemo.so
C++ exception while wrapping module M: No appropriate factory for type v
ERROR: LoadError: No appropriate factory for type v
Stacktrace:
[1] register_julia_module
@ ~/.julia/packages/CxxWrap/I0P2E/src/CxxWrap.jl:432 [inlined]
[2] readmodule(so_path_cb::Main.M.var"#1#2", funcname::Symbol, m::Module, flags::Nothing)
@ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/I0P2E/src/CxxWrap.jl:825
[3] wrapmodule(so_path_cb::Function, funcname::Symbol, m::Module, flags::Nothing)
@ CxxWrap.CxxWrapCore ~/.julia/packages/CxxWrap/I0P2E/src/CxxWrap.jl:835
in expression starting at /home/user/tmp/demo.jl:1
C++ compiler for the host machine: clang++ (clang 14.0.0-1ubuntu1 "Ubuntu clang version 14.0.0-1ubuntu1.1")
On my system this bash script
produces the following output:
C++ compiler for the host machine:
clang++ (clang 14.0.0-1ubuntu1 "Ubuntu clang version 14.0.0-1ubuntu1.1")