So I was working on a C++ project on Xcode, and I updated to the latest version of Xcode with recommended default settings; then I started having the following errors:
dyld: Library not loaded: /usr/local/lib/libcryptopp.dylib
Referenced from: /Users/devharsh/Library/Developer/Xcode/DerivedData/server-bohvcuztzndrrzhcoglrvuijfasj/Build/Products/Debug/server
Reason: no suitable image found. Did find:
/usr/local/lib/libcryptopp.dylib: code signature in (/usr/local/lib/libcryptopp.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/lib/libcryptopp.dylib: code signature in (/usr/local/lib/libcryptopp.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/lib/libcryptopp.dylib: code signature in (/usr/local/lib/libcryptopp.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
Solution:
- Go to Xcode > Targets > Build Settings
- Scroll down and go to the Signing tab
- Click on "Enable Hardened Runtime" and set it to "No"
- Recompile, and it should be fixed
This macOS error comes from Library Validation, a security feature that requires loaded libraries to be signed by the same team as the app. After an Xcode update turned on the hardened runtime, the app refused to load a third party dylib such as libcryptopp.
The usual fixes are to turn off the Library Validation option in the target's hardened runtime settings during development, or to sign the dylib with the same identity as the app so the signatures match.