0

Might be a very obvious thing to do, but I'm stuck on trying to build a bsdtar that uses a custom build version of liblzma.dylib, so I can share both the bsdtar binary and the liblzma.dylib library together.

Thanks to Tsyvarev comment, I'm building bsdtar with the custom the dylib, simply calling:

cmake -DCMAKE_PREFIX_PATH=customlib

No more need to use FIND_PACKAGE(liblzma HINTS customlib customlib/include) or similar. During the cmake process, the output looks like this:

-- Looking for lzma_auto_decoder in /libarchive-3.3.2/customlib/liblzma.dylib
-- Looking for lzma_auto_decoder in /libarchive-3.3.2/customlib/liblzma.dylib - found
-- Looking for lzma_easy_encoder in /libarchive-3.3.2/customlib/liblzma.dylib
-- Looking for lzma_easy_encoder in /libarchive-3.3.2/customlib/liblzma.dylib - found
-- Looking for lzma_lzma_preset in /libarchive-3.3.2/customlib/liblzma.dylib
-- Looking for lzma_lzma_preset in /libarchive-3.3.2/customlib/liblzma.dylib - found
-- Found LibLZMA: /libarchive-3.3.2/customlib/include (found version "5.2.3")

Anyway, the final build of bsdtar still looks for the system dylib, instead of the custom one:

aone$ otool -L libarchive-3.3.2/bin/bsdtar 
libarchive-3.3.2/bin/bsdtar:
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/local/lib/liblzma.5.dylib (compatibility version 8.0.0, current version 8.3.0)
    ...

The folder customlib contains liblzma.5.dylib, it's alias liblzma.dylib and liblzma.a. The folder customlib/import contains lzma.h and and lzma folder with the rest of the headers.

Anyone has any clue how to do it properly? Thanks in advance.

Just asked it here: https://github.com/libarchive/libarchive/issues/1014

aone
  • 57
  • 8
  • If you want to hint `find_package()` command about installation of your package, use `CMAKE_PREFIX_PATH` variable, as described in [this answer](https://stackoverflow.com/questions/34795816/hinting-findname-cmake-files-with-a-custom-directory/34797156#34797156). Do not forget to clear CMake cache after adding a hint. – Tsyvarev Apr 26 '18 at 17:47
  • This worked wonderfully! Did not needed the hint anymore. I'm gonna edit my question, since the final product still looks for the system dylib. – aone Apr 27 '18 at 11:29
  • Looks like RPATH problem to me: path `/usr/local/lib/` is contained in the *LD_LIBRARY_PATH* variable (or its analogue on MacOS), so dynamic loader finds `liblzma.5.dylib` file under `/usr/local/lib/` before `/libarchive-3.3.2/customlib/`. I don't know how to handle this properly. – Tsyvarev Apr 27 '18 at 11:53
  • did some test exporting `LD_LIBRARY_PATH` and `DYLD_LIBRARY_PATH` with no luck :( – aone Apr 28 '18 at 08:52

1 Answers1

0

Finally did it post compilation with install_name_tool (man):

install_name_tool -change "/usr/local/lib/liblzma.5.dylib" "customlib/liblzma.dylib" bsdtar 
aone
  • 57
  • 8