简体   繁体   中英

copy libpq.5.dylib to /usr/lib/libpq.5.dylib

I can't load packages in R because the file libpq.5.dylib is not in /usr/lib/libpq.5.dylib . It is in /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib

I tried this line: sudo ln -s /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib /usr/lib/libpq.5.dylib but I get this response: ln: /usr/lib/libpq.5.dylib: Operation not permitted

What can I do to get the file in /usr/lib/libpq.5.dylib without causing issues? This solution suggests that I may face problems down the line so I don't understand what to do.

You really don't want it in /usr/lib . Apple declared that as off-limits, and on newer macOS versions it lives on a read-only volume. Unless you're willing to go into recovery mode and manually tamper with the volume (and possibly repeat that on future OS updates), this is not the way to go.

Instead, let's address the core issue:
Dynamic libraries on macOS embed their own install path inside the binary, and the linker copies that into binaries linking against them. This information can be changed with install_name_tool (see man install_name_tool ).

  1. Examine the install name of the dylib:

     otool -l /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib | fgrep -A2 LC_ID_DYLIB

    If the printed path already points to the dylib itself (or a path that is symlinked to it), use this path as [new_path] below, and skip step 2.

  2. If the dylib's install name does not point back to itself, run this:

     sudo install_name_tool -id /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib

    And use /usr/local/Cellar/libpq/13.0/lib/libpq.5.dylib for [new_path] below.

  3. For binaries that link against the dylib, run:

     sudo install_name_tool -change /usr/lib/libpq.5.dylib [new_path] [path_to_binary]

I had the same issue building a container through docker for API use : RPostgres was installed but the library couldn't load, same error message. Since I had installed Postgres on my machine, I figure the problem was worked around therefore I had no such message on local ; but here's how I solved this in my dockerfile, 100% verified on a machine with nothing related to R installed :

RUN apt-get update && apt-get install libpq5 -y

So executing apt-get update && apt-get install libpq5 -y on your terminal should do the trick. Light and efficient.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM