Call C++ library

I want to control this equipment using the libraries provided by the manufacturer: libm2k: libm2k::analog::DMM Class Reference

I tried to install Cxx on Julia 1.5 but I got and error:

julia> using Cxx
[ Info: Precompiling Cxx [a0b5b9ef-44b7-5148-a2d1-f6db19f3c3d2]
ERROR: LoadError: LoadError: could not load library "C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\..\deps\usr\bin\libcxxffi"
The specified procedure could not be found.
Stacktrace:
 [1] dlopen(::String, ::UInt32; throw_error::Bool) at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Libdl\src\Libdl.jl:109
 [2] dlopen at D:\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.5\Libdl\src\Libdl.jl:109 [inlined]
 [3] init_libcxxffi() at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\initialization.jl:23
 [4] top-level scope at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\initialization.jl:25
 [5] include(::Function, ::Module, ::String) at .\Base.jl:380
 [6] include at .\Base.jl:368 [inlined]
 [7] include(::String) at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\Cxx.jl:144
 [8] top-level scope at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\Cxx.jl:170
 [9] include(::Function, ::Module, ::String) at .\Base.jl:380
 [10] include(::Module, ::String) at .\Base.jl:368
 [11] top-level scope at none:2
 [12] eval at .\boot.jl:331 [inlined]
 [13] eval(::Expr) at .\client.jl:467
 [14] top-level scope at .\none:3
in expression starting at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\initialization.jl:25
in expression starting at C:\Julia 1.5.1\.julia\packages\Cxx\1RaOv\src\Cxx.jl:170

Is Cxx not compatible with Julia 1.5?

No, it is not. You can give GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in Julia a try.

Thank you for the suggestion!
Let me know if I understood correctly the way CxxWrap works:
I need to write some C++ code which calls the vendor library, along with the code that defines Julia modules. Then compile this and call it from Julia using CxxWrap?
Does this mean that this self-written/compiled library acts as an intermediary between Julia and the vendor library?

Or did I understand everything backwards and I actually need to hack into the source code of the vendor library and compile it?( Pretty much impossible for me)

Sorry, the questions might seem stupid but I’m a noob and never worked with C++ or CxxWrap.

Yes, this is correct. For example https://github.com/barche/QML.jl uses CxxWrap and here is the glue code: https://github.com/barche/jlqml. You can find other packages using CxxWrap here: JuliaHub.

2 Likes

I found JuliaCon 2020 | Wrapping a C++ Library with CxxWrap.jl - YouTube which looks like a nice tutorial,but since I’m using Windows I need to compile my own libcxxwrap-julia and I’m stuck.
I cloned the git repo using Visual Studio but when I right clik to build on the CMakeLists.txt I get “No target architecture” error.
There is also some info about a “Julia_PREFIX” which I should set but it’s not clearly explained which file to edit. I fiddled around the CMake settings in Visual studio and found the paths to the julia executable and library were already magically set…
Is there a “for dummies” step by step tutorial on building this? I don’t know how to use Cmake.