Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

macOS: Homebrew dylib formula all hit code-sign errors

On macOS, I used to work with dynamic libraries installed via Homebrew with issues.

But with my latest setup:

  • Mojave 10.14.6
  • Xcode 11.2.1

I start getting code sign problems with the libs that used to work, such as protobuf.

Below is the console output when running a successfully built project:


dyld: Library not loaded: /usr/local/opt/protobuf/lib/libprotobuf.22.dylib
  Referenced from: /path/to/myproj/_build/Debug/mam-host
  Reason: no suitable image found.  Did find:
    /usr/local/opt/protobuf/lib/libprotobuf.22.dylib: code signature in (/usr/local/opt/protobuf/lib/libprotobuf.22.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
    /usr/local/Cellar/protobuf/3.11.1/lib/libprotobuf.22.dylib: code signature in (/usr/local/Cellar/protobuf/3.11.1/lib/libprotobuf.22.dylib) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
Program ended with exit code: 9

What should I do?

Should I just

codesign -s "Mac Developer: me" /usr/local/opt/protobuf/lib/libprotobuf.22.dylib

Or do I have to build from source?

P.S. After running codesign command above I got the exact same error.

like image 210
kakyo Avatar asked Dec 06 '19 13:12

kakyo


1 Answers

Finally solved it.

You have two options:

  • Option 1 Disable checking on code-signing for libs: Project Settings > Signing & Capabilities > Hardened Runtime > Runtime Exceptions > Diable Library Validation
  • Option 2: Code-sign libs using your code-signing identity, e.g. Apple Development: Your Name (10-char-ID)
    • Remove public signature: codesign --remove-signature /path/to/theirlib.dylib
    • Sign with project signature: codesign -s "Apple Development: Your Name (10-char-ID)" /path/to/theirlib.dylib
like image 54
kakyo Avatar answered Oct 02 '22 08:10

kakyo