# Compiling shared C libraries for julia in macOS

**URL:** <https://discourse.julialang.org/t/compiling-shared-c-libraries-for-julia-in-macos/2577>\
**Category:** General Usage\
**Created:** [March 9, 2017, 8:45pm UTC](https://discourse.julialang.org/t/compiling-shared-c-libraries-for-julia-in-macos/2577 "2017-03-09T20:45:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chkwon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chkwon/32/3632_2.png) [@chkwon](https://discourse.julialang.org/u/chkwon)\
**Post date:** [March 9, 2017, 8:45pm UTC](https://discourse.julialang.org/t/compiling-shared-c-libraries-for-julia-in-macos/2577/1 "2017-03-09T20:45:44Z")

</div>

I have two C libraries `libfoo` and `libbar`, and `libbar` requires `libfoo`. I need to call `libbar` from julia in macOS. I need to compile them separately.

1. How to compile them? Should they need to be `dylb` file, or are `so` files okay as well? Are `libfoo.so` and `libfbar.dylb` okay? Or something else?

2. How to open them in julia? Can I just open `libbar.dylb` or `libbar.so` in julia, or should I open both `libfoo` and `libbar` in julia? Should either library path be placed in `DYLB_LIBRARY_PATH` or `LD_LIBRARY_PATH`?

---

<div class="post-metadata">

**Author:** ![barche](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barche/32/79_2.png) [@barche](https://discourse.julialang.org/u/barche)\
**Post date:** [March 9, 2017, 9:23pm UTC](https://discourse.julialang.org/t/compiling-shared-c-libraries-for-julia-in-macos/2577/2 "2017-03-09T21:23:19Z")

</div>

On macOS shared libraries have the .dylib extension. The libraries are typically found by setting the rpath, for example this links libhello.dylib to libcxxwrap and libjulia:

```bash
clang++ -dynamiclib -Wl,-headerpad_max_install_names -o libhello.dylib -install_name @rpath/libhello.dylib CMakeFiles/hello.dir/hello.cpp.o -Wl,-rpath,/Users/user/src/julia/CxxWrap/deps/usr/lib /Users/user/src/julia/CxxWrap/deps/usr/lib/libcxx_wrap.0.1.dylib /usr/local/Cellar/julia/0.5.0/lib/libjulia.dylib

```

Using `DYLB_LIBRARY_PATH` is not recommended.
