2

I have a requirement to copy a dylib file to /usr/lib folder. Even though I have disabled csruitl in recovery mode to bypass the SIP. Still I cannot copy this file to the /usr/lib folder. I have also tried sudo cp libstdc+.dylib /usr/lib/, but no luck.

From some other articles I have read - unable to copy to /usr/lib - I am suggested to copy the dylib file to /usr/local/lib with the install_name_tool.

If my target location is /usr/lib, the file is libstdc+.dylib, and if i put my file into the suggested location /usr/local/lib, then what should my command be in Terminal?

Or is there any easier way to do this? Would anyone please help?

6
  • Big Sur has a Sealed System Volume. Changing /usr/lib/ will probably break the seal.
    – lhf
    Commented Dec 31, 2021 at 12:24
  • 2
    Where is the requirement coming from, which binary/application asks for this? Is it usr/lib or /usr/lib?
    – nohillside
    Commented Dec 31, 2021 at 12:27
  • What is giving you this requirement?
    – mmmmmm
    Commented Dec 31, 2021 at 12:50
  • 1
    The easy way is to use a package manager like Macports or Homebrew to build the libraries
    – mmmmmm
    Commented Dec 31, 2021 at 12:51
  • 1
    Which application are you trying to install (the one which requires something to be in /usr/lib)? If it is one of yours, fix it; if it is from a 3rd party, have it fixed.
    – nohillside
    Commented Dec 31, 2021 at 15:37

2 Answers 2

2

The command in the Terminal would look like this:

install_name_tool -change BEFORE AFTER MYPROGRAM

This updates the information inside the MYPROGRAM file from searching for the dylib as BEFORE to searching for it as AFTER.

So for example if your program is ~/office/mytool and it was previously set to load /usr/lib/libstdc++.dylib and you've now placed that file in ~/office/libstdc++.dylib instead, the command would look like this:

install_name_tool -change /usr/lib/libstdc++.dylib ~/office/libstdc++.dylib ~/office/mytool

Note that instead of hard-coding the paths, you can use various identifiers such as @executable_path to refer to dynamic paths.

Also note that it might not be immediately obvious what the program was setup to look for exactly. I would advise starting by getting that information from the program by running:

otool -L ~/office/mytool

In addition you should know that instead of manipulating the program binary itself, it is sometimes easier to set the new load path using an environment variable. I.e. instead of running your program like this:

./mytool

then run it like this:

DYLD_LIBRARY_PATH=/usr/local/lib ./mytool
1

So, this won’t be easy if you’re not able to modify the package build to look in /usr/local/lib.

Pasting the files in the new location is trivial but won’t fix the root problem of needing to modify the path for the code to understand it can’t simply reuse a system protected location.

I would go back and look at changing your requirements now that you’ve learned the protected nature of the sealed system on macOS.

2
  • I think you're overlooking that modifying the path in the code and as such modifying the package is exactly what the "install_name_tool" that this question is about does.
    – jksoegaard
    Commented Jan 30, 2022 at 23:27
  • Your answer is the only feasible option - since OP can’t reasonably inject code into the protected folders like they ask.
    – bmike
    Commented Jan 31, 2022 at 0:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .