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?

nohillside
  • 100,768
yts61
  • 121
  • Big Sur has a Sealed System Volume. Changing /usr/lib/ will probably break the seal. – lhf Dec 31 '21 at 12:24
  • 2
    Where is the requirement coming from, which binary/application asks for this? Is it usr/lib or /usr/lib? – nohillside Dec 31 '21 at 12:27
  • What is giving you this requirement? – mmmmmm Dec 31 '21 at 12:50
  • 1
    The easy way is to use a package manager like Macports or Homebrew to build the libraries – mmmmmm Dec 31 '21 at 12:51
  • We had a project running in my previous intel Mac using this file. It was easy to copy and paste the file to /usr/lib. I just disabled SIP, then copied and pasted, then turned back on SIP. But now, with my new M1 Mac, I just can't replicate the process. Would you please share with me some sample codes of Macports? Like how it will be like? I just need to paste a file into this folder, that's it. I have Homebrew in my M1 because I use Python often. – yts61 Dec 31 '21 at 15:15
  • 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 Dec 31 '21 at 15:37

2 Answers2

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
jksoegaard
  • 77,783
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.

bmike
  • 235,889
  • 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 Jan 30 '22 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 Jan 31 '22 at 00:23