# Call C++ library

**URL:** https://discourse.julialang.org/t/call-c-library/51856
**Category:** General Usage
**Tags:** cxx
**Created:** [December 15, 2020, 9:37am UTC](https://discourse.julialang.org/t/call-c-library/51856 "2020-12-15T09:37:00Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [December 15, 2020, 9:37am UTC](https://discourse.julialang.org/t/call-c-library/51856/1 "2020-12-15T09:37:00Z")

</div>

I want to control this equipment using the libraries provided by the manufacturer: [libm2k: libm2k::analog::DMM Class Reference](https://analogdevicesinc.github.io/libm2k/classlibm2k_1_1analog_1_1_d_m_m.html)

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

```julia
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?

---

<div class="post-metadata">

### Author: ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)
#### Post date: [December 15, 2020, 9:47am UTC](https://discourse.julialang.org/t/call-c-library/51856/2 "2020-12-15T09:47:41Z")

</div>

No, it is not. You can give [GitHub - JuliaInterop/CxxWrap.jl: Package to make C++ libraries available in Julia](https://github.com/JuliaInterop/CxxWrap.jl) a try.

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [December 15, 2020, 10:03am UTC](https://discourse.julialang.org/t/call-c-library/51856/3 "2020-12-15T10:03:52Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![thofma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thofma/32/1691_2.png) [@thofma](https://discourse.julialang.org/u/thofma)
#### Post date: [December 15, 2020, 10:16am UTC](https://discourse.julialang.org/t/call-c-library/51856/4 "2020-12-15T10:16:17Z")

</div>

Yes, this is correct. For example [https://github.com/barche/QML.jl](https://github.com/barche/QML.jl) uses CxxWrap and here is the glue code: [https://github.com/barche/jlqml](https://github.com/barche/jlqml). You can find other packages using CxxWrap here: [JuliaHub](https://juliahub.com/ui/Packages/CxxWrap/WGIJU/0.11.0?t=2).

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [December 28, 2020, 4:36pm UTC](https://discourse.julialang.org/t/call-c-library/51856/5 "2020-12-28T16:36:51Z")

</div>

I found [JuliaCon 2020 | Wrapping a C++ Library with CxxWrap.jl - YouTube](https://www.youtube.com/watch?v=VoXmXtqLhdo) 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.
