美文网首页
OpenCV动态库未签名问题

OpenCV动态库未签名问题

作者: 山已几孑 | 来源:发表于2019-11-28 22:44 被阅读0次

    copy的,觉得肯定会再遇到,自己留个档
    遇到的问题:

    最近在尝试使用动态库,编译没有问题,但运行时报错,这对于第一次使用动态库来说,简直是个巨大的打击。开始一直以为动态库没能加载是路径选择错误,浪费的大把时间。仔细看日志后,发现动态库居然要签名,不签名就不让用,好像是从maxOS 10.14开始搞的事情:

    dyld: Library not loaded: /usr/local/opt/opencv/lib/libopencv_flann.4.1.dylib
    Referenced from: /Users/xxx/Library/Developer/Xcode/DerivedData/OpenCV-frdcgrfkxsvbyahjaonnyllerinn/Build/Products/Debug/OpenCV
    Reason: no suitable image found. Did find:
    /usr/local/opt/opencv/lib/libopencv_flann.4.1.dylib: code signature in (/usr/local/opt/opencv/lib/libopencv_flann.4.1.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/libopencv_flann.4.1.dylib: code signature in (/usr/local/lib/libopencv_flann.4.1.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/opencv/4.1.1_2/lib/libopencv_flann.4.1.1.dylib: code signature in (/usr/local/Cellar/opencv/4.1.1_2/lib/libopencv_flann.4.1.1.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.
    

    关键错误信息是:code signature in (*.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.

    安装错误提示,需要对dylib进行签名。

    签名步骤:

    1. 复制证书名称

    先打开keychain Access.app (中文名是:钥匙串访问),选择你的证书,复制证书名称。到括号之前就行


    证书名称
    1. 签名命令如下:

    codesign -f -s "Mac Developer: 你的开发者邮箱" xxx.dylib
    1
    当你对报错的dylib进行签名后,会发现还要你对别的dylib也签名,于是就陷入了签名的死循环里,不停的签名。

    1. 解决签名的循环坑:

    直接将系统的全部dylib都进行签名:

    codesign -f -s "Mac Developer: 你的开发者邮箱" /usr/local/opt//lib/.dylib
    1
    该命令将目录/usr/local/opt下的全面dylib都进行了签名,也就是说,XCode编译代码时依赖的系统库,全部都被签名了。如果你还依赖了别的动态库,需要再单独进行签名。

    总结:

    动态库引入签名,本意是好的,但是强制要求签名,还是挺坑人的。

    关于签名的其他命令操作:

    清除动态库的签名:
    codesign --remove-signature xxx.dylib
    1
    查看签名:
    codesign -v xxx.dylib
    1
    重新签名:
    codesign的-f参数就是强制签名的意思,本文使用的codesign -f -s就能直接重新签名。如果不想覆盖原来的签名,可以把-f参数去掉。
    ————————————————
    版权声明:本文为CSDN博主「ReadyShowShow」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/ReadyShowShow/article/details/102547633

    相关文章

      网友评论

          本文标题:OpenCV动态库未签名问题

          本文链接:https://www.haomeiwen.com/subject/tkwiwctx.html