[cmake] [macOS] building the shared library does not set `install_name`

Open Beginner friendly
#4,983 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, cmake
Domain
build-system

Research direction

Start by comparing the CMake shared library configuration with the macOS install name settings in lib/Makefile (the issue links to lines 78–83). Reproduce the discrepancy with the provided CMake build and install steps, then use otool -D to check the library ID. Done when the CMake-built library has the expected install name behavior on macOS.

Written by the indexing model from the issue text.

Description

Description

[!NOTE]

This issue applies only to macOS.

When building libzstd shared lib with GNU Make, by default, it sets the install_name for the lib as seen at

https://github.com/meta/zstd/blob/98e7b6ac7a08d9cea44aa7b0f6328e064259e625/lib/Makefile#L78-L83

On the other hand, building libzstd shared lib with CMake, it does not.

Expected behavior

Since make is the main build system for libzstd, CMake should also follow the behavior and set the install_name for the shared lib as well.

Reproduction

  1. Clone the repository: git clone https://github.com/meta/zstd

  2. Change directory to zstd dir: cd zstd

  3. Build: make PREFIX=/opt/libzstd-make

  4. Install: sudo make PREFIX=/opt/libzstd-make install

  5. Print the install_name id: otool -D /opt/libzstd-make/lib/libzstd.1.6.0.dylib

  6. Configure with CMake:

    cmake \
        -DCMAKE_BUILD_TYPE=Release \
        --install-prefix /opt/libzstd-cmake \
        -S . \
        -B /tmp/build-libzstd
    
  7. Build with CMake: cmake --build /tmp/build-libzstd --config Release

  8. Install with CMake: sudo cmake --install /tmp/build-libzstd --config Release

  9. Print the install_name id: otool -D /opt/libzstd-cmake/lib/libzstd.1.6.0.dylib

  10. Check the output of step (5.) is /opt/libzstd-make/lib/libzstd.1.dylib while the output of step (9.) is @rpath/libzstd.1.dylib


[!TIP]

In case there is interest, I already fixed it locally and I can submit a PR for the fix.

Dominant language
C
Stars
28.1k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from facebook/zstd

All issues in facebook/zstd

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.