JuliaInterop / CxxWrap.jl

Package to make C++ libraries available in Julia
Other
418 stars 67 forks source link

Simple tutorials/examples #127

Closed musm closed 5 years ago

musm commented 5 years ago

Is there any additional more tutorial style documentation available? Currently MATLAB.jl wraps the C api, but this has severe limitations and reduced functionality when compared to the Cpp api. I'd like to wrap the Cpp API, but I'm a beginner and don't often use cpp so would like some simple tutorial on how to use this package.

BTW does it matter if we use cpp libs compiled with msvc toolchain in julia? I know when using C I have to use a mingw based toolchain or else it won't load.

barche commented 5 years ago

I think the current examples are a good starting point, for example the C++ code for the types example shows how to add non-template types and functions: https://github.com/JuliaInterop/libcxxwrap-julia/blob/master/examples/types.cpp#L142 This is loaded on the Julia side here: https://github.com/JuliaInterop/CxxWrap.jl/blob/master/test/types.jl

One difference between the examples and a real module is that they lack an __init__ function, which is required for precompilation.

I recently updated QML.jl so that is also a working example. The C++ site is in a separate repository at: https://github.com/barche/jlqml

For MSVC, it should work well, but libcxxwrap-julia must be compiled with MSVC as well. There are actually binaries for that available here, but they are not used automatically, so you have to extract them and set the JLCXX_DIR environment variable to the directory where they are unpacked.

musm commented 5 years ago

I'm having a hard time figuring out where exactly libcxxwrap-julia / jlcxx exist?

The current README is for juliapro and for an older version of julia. With the newest Pkg manager the directories are kinda hard to locate.

barche commented 5 years ago

Ah yes, I forgot about that. You can locate it using:

using CxxWrap
dirname(dirname(CxxWrap.libcxxwrap_julia))

Or if you want something more predictable for development, you can extract or build libcxxwrap where you want, and point CxxWrap to it by setting JLCXX_DIR and then doing Pkg.build on CxxWrap