# CxxWrap can't find .dylib on MacOS

**URL:** https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997
**Category:** General Usage
**Tags:** cxx, cxxwrap
**Created:** [September 9, 2022, 3:36pm UTC](https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997 "2022-09-09T15:36:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![danny.s](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@danny.s](https://discourse.julialang.org/u/danny.s)
#### Post date: [September 9, 2022, 3:36pm UTC](https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997/1 "2022-09-09T15:36:35Z")

</div>

I’m working on a C++ package (called MParT) for MacOS and Linux, as well as creating bindings to it in Julia. So far, I’ve had moderate success, where I can use Linux to `]add https://github.com/MeasureTransport/MParT.jl` (the Julia-side bindings) and Julia downloads the appropriate tarball from [MParT\_jll](https://github.com/JuliaBinaryWrappers/MParT_jll.jl) published via Yggdrasil. However, when someone tries to do the same on a MacOS device, MParT fails to precompile, [saying](https://github.com/MeasureTransport/MParT.jl/runs/8231771408?check_suite_focus=true#step:6:319)

```julia
ERROR: LoadError: could not load library "libmpartjl"
dlopen(libmpartjl.dylib, 1): image not found
...

```

which is bizarre, because if you look in the tarball provided at MParT\_jll, which looks correct (it provides the correct dylib files in the correct directories). Any help would be greatly appreciated!!

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [September 9, 2022, 4:30pm UTC](https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997/2 "2022-09-09T16:30:37Z")

</div>

Shouldn’t you be referring to the library as `libmpartjl` (a symbol exported by `MParT_jll` — this is a constant string containing the full path of the library) rather than by the string `"libmpartjl"`?

---

<div class="post-metadata">

### Author: ![danny.s](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@danny.s](https://discourse.julialang.org/u/danny.s)
#### Post date: [September 12, 2022, 1:46pm UTC](https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997/3 "2022-09-12T13:46:30Z")

</div>

Just to be clear, are you suggesting using the macro `wrapmodules` as

```julia
@wrapmodules libmpartjl

```

? The git repo seems to use those interchangably in its examples/readme, but that might be it. I’ll edit and mark as solution once things get merged if this solves it.

---

<div class="post-metadata">

### Author: ![danny.s](https://avatars.discourse-cdn.com/v4/letter/d/41988e/32.png) [@danny.s](https://discourse.julialang.org/u/danny.s)
#### Post date: [September 12, 2022, 2:41pm UTC](https://discourse.julialang.org/t/cxxwrap-cant-find-dylib-on-macos/86997/4 "2022-09-12T14:41:53Z")

</div>

For the record, after @stevengj 's proposed solution, the same issue is still there when precompiling. Here’s a full error log

```julia
[Info: Precompiling MParT [4383ffe1-dc98-4547-9515-b1eacdbc2dac]
ERROR: LoadError: UndefVarError: libmpartjl not defined
Stacktrace:
 [1] top-level scope
   @ ~/opt/anaconda3/envs/mpart/share/julia/packages/MParT/1POGA/src/MParT.jl:18
 [2] include
   @ ./Base.jl:418 [inlined]
 [3] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
   @ Base ./loading.jl:1318
 [4] top-level scope
   @ none:1
 [5] eval
   @ ./boot.jl:373 [inlined]
 [6] eval(x::Expr)
   @ Base.MainInclude ./client.jl:453
 [7] top-level scope
   @ none:1
in expression starting at ~/opt/anaconda3/envs/mpart/share/julia/packages/MParT/1POGA/src/MParT.jl:2
ERROR: Failed to precompile MParT [4383ffe1-dc98-4547-9515-b1eacdbc2dac] to ~/opt/anaconda3/envs/mpart/share/julia/compiled/v1.7/MParT/jl_nSRJS0.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, ignore_loaded_modules::Bool)
   @ Base ./loading.jl:1466
 [3] compilecache(pkg::Base.PkgId, path::String)
   @ Base ./loading.jl:1410
 [4] _require(pkg::Base.PkgId)
   @ Base ./loading.jl:1120
 [5] require(uuidkey::Base.PkgId)
   @ Base ./loading.jl:1013
 [6] require(into::Module, mod::Symbol)
   @ Base ./loading.jl:997

```

Something to note that I just found-- I’m loading multiple modules from the same library, and this is not able to find the library for the second module I want to wrap, i.e. the _second_ time I load the library there is an error. It seems like if I comment that out and only load one module from the library, everything works okay.
