Compiling shared C libraries for julia in macOS

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?

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:

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.