{"id":579,"date":"2012-12-07T11:31:34","date_gmt":"2012-12-07T03:31:34","guid":{"rendered":"http:\/\/xujiwei.com\/blog\/?p=579"},"modified":"2016-12-27T17:00:21","modified_gmt":"2016-12-27T09:00:21","slug":"a-shell-script-for-fixing-library-load-path","status":"publish","type":"post","link":"https:\/\/xujiwei.com\/blog\/2012\/12\/a-shell-script-for-fixing-library-load-path\/","title":{"rendered":"\u4e00\u4e2a\u4fee\u6b63 Mach-O \u6587\u4ef6\u52a0\u8f7d\u5171\u4eab\u5e93\u8def\u5f84\u7684\u811a\u672c"},"content":{"rendered":"<p>\u5728 Mac \u4e0a\u7528\u5230\u4e00\u4e9b\u5f00\u6e90\u7684\u7a0b\u5e8f\uff0c\u7ecf\u5e38\u9700\u8981\u81ea\u5df1\u7f16\u8bd1\uff0c\u8fd9\u4e2a\u65f6\u5019\u4e00\u822c\u4f1a\u4f7f\u7528 <a href=\"http:\/\/www.macports.org\/\">macports<\/a> \u6240\u63d0\u4f9b\u7684\u5de5\u5177\u94fe\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<p>\u5728\u7f16\u8bd1\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5f00\u6e90\u7a0b\u5e8f\u6240\u5f15\u7528\u7684\u5404\u79cd\u5176\u4ed6\u5e93\uff0c\u4f8b\u5982 libssl\u3001libz\u3001libgd \u4e4b\u7c7b\u7684\uff0c\u4e00\u822c\u90fd\u4f1a\u5728 \/opt\/local\/lib \u4e0b\uff0c\u800c\u5982\u679c\u628a\u8fd9\u4e2a\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u7ed9\u5176\u4ed6\u4eba\u7528\u65f6\uff0c\u5982\u679c\u5176\u4ed6\u4eba\u6ca1\u6709\u5b89\u88c5 macports\uff0c\u90a3\u4e48\u5c31\u4f1a\u7f3a\u5931\u8fd9\u4e9b\u5171\u4eab\u5e93\uff0c\u4ece\u800c\u5bfc\u81f4\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236\u7a0b\u5e8f\u65e0\u6cd5\u8fd0\u884c\u3002<\/p>\n<p>\u5177\u4f53\u539f\u56e0\u5c31\u662f\u56e0\u4e3a Mac \u4e0b\u94fe\u63a5\u5171\u4eab\u5e93\u65f6\uff0c\u4f1a\u5728\u94fe\u63a5\u65f6\u5c06\u5171\u4eab\u5e93\u7684\u8def\u5f84\u5199\u5165\u5230\u6700\u7ec8\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\uff0c\u800c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fd9\u4e2a\u8def\u5f84\u662f\u7edd\u5bf9\u8def\u5f84\uff0c\u4f8b\u5982 \/opt\/local\/lib\/libz.1.dylib\u3002<\/p>\n<p>\u6240\u5e78\u82f9\u679c\u63d0\u4f9b\u4e86 install_name_tool \u8fd9\u4e2a\u5de5\u5177\u6765\u4fee\u6539\u5171\u4eab\u5e93\u7684\u8def\u5f84\u3002<\/p>\n<p>\u4e0b\u9762\u8fd9\u4e2a\u811a\u672c\u5c31\u662f\u7528\u6765\u6279\u91cf\u66ff\u6362\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u7684\u5171\u4eab\u5e93\u8def\u5f84\u3002<\/p>\n<p>\u8fd9\u4e2a\u811a\u672c\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa lib \u76ee\u5f55\uff0c\u5c06\u4e8c\u8fdb\u5236\u6587\u4ef6\u6240\u4f9d\u8d56\u7684 \/opt\/local\/lib \u4e2d\u7684\u5171\u4eab\u5e93\u590d\u5236\u5230 lib \u76ee\u5f55\u4e2d\uff0c\u5e76\u4fee\u6539\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u4fdd\u5b58\u7684\u5171\u4eab\u5e93\u7684\u8def\u5f84\u3002<\/p>\n<p><script src=\"https:\/\/gist.github.com\/4225568.js\"> <\/script><\/p>\n<p>\u811a\u672c\u7684\u4f7f\u7528\u65b9\u6cd5\uff0c\u5c06\u4e0a\u9762\u7684\u811a\u672c\u4fdd\u5b58\u4e3a fixlibpath.sb\uff0c\u5e76\u52a0\u4e0a\u53ef\u6267\u884c\u6743\u9650\uff0c\u653e\u5230\u8981\u4fee\u6b63\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u6240\u5728\u7684\u76ee\u5f55\uff1a<\/p>\n<pre><code>chmod +x fixlibpath.sh\n.\/fixlibpath.sh mybinary\n<\/code><\/pre>\n<p>\u8fd8\u6709\u5171\u4eab\u5e93\u4f1a\u4f9d\u8d56\u5176\u4ed6\u5171\u4eab\u5e93\u7684\u60c5\u51b5\uff0c\u6240\u4ee5\u4e5f\u9700\u8981\u5bf9 lib \u4e2d\u590d\u5236\u8fc7\u6765\u7684\u5171\u4eab\u5e93\u8fdb\u884c\u540c\u6837\u7684\u5904\u7406\uff1a<\/p>\n<pre><code>for f in lib\/*; do\n    .\/fixlibpath.sh $f\ndone\n<\/code><\/pre>\n<p>\u53ef\u4ee5\u89c2\u5bdf\u4e00\u4e0b\u811a\u672c\u7684\u8f93\u51fa\uff0c\u5982\u679c\u8f93\u51fa\u7684\u5185\u5bb9\u4e2d\uff0c\u6bcf\u4e2a\u5171\u4eab\u5e93\u6240\u4f9d\u8d56\u7684\u5e93\u8def\u5f84\u4e2d\u4e0d\u5b58\u5728 \/opt\/local\/lib\uff0c\u90a3\u5c31\u8868\u793a\u5904\u7406\u5b8c\u6210\u4e86\u3002\u6bcf\u4e2a\u5171\u4eab\u5e93\u90fd\u4f1a\u6709\u4e00\u4e2a \/opt\/local\/lib \u8def\u5f84\u7684\uff0c\u4f46\u662f\u540d\u79f0\u4e0e\u8fd9\u4e2a\u5171\u4eab\u5e93\u4e00\u6837\u7684\u8def\u5f84\uff0c\u8fd9\u4e2a\u662f\u4e0d\u7528\u5904\u7406\u7684\u3002<\/p>\n<p>\u8981\u6d4b\u8bd5\u5904\u7406\u5b8c\u6210\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u662f\u5426\u6b63\u5e38\uff0c\u53ef\u4ee5\u5c06\u8be5\u4e8c\u8fdb\u5236\u6587\u4ef6\u548c lib \u76ee\u5f55\u590d\u5236\u5230\u4e00\u53f0\u6ca1\u6709\u5b89\u88c5 macports \u6216\u8005\u6ca1\u6709 macports \u5b89\u88c5\u76f8\u5173\u5171\u4eab\u5e93\u7684\u673a\u5668\u4e0a\u8fd0\u884c\uff0c\u5982\u679c\u80fd\u6b63\u5e38\u8fd0\u884c\u5c31\u8868\u793a\u5904\u7406\u6210\u529f\u4e86\u3002<\/p>\n<h2>\u53c2\u8003\u8d44\u6599<\/h2>\n<ol>\n<li><a href=\"http:\/\/www.mikeash.com\/pyblog\/friday-qa-2009-11-06-linking-and-install-names.html\">http:\/\/www.mikeash.com\/pyblog\/friday-qa-2009-11-06-linking-and-install-names.html<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/4677044\/how-to-use-dylib-in-mac-os-x-c#answer-11585225\">http:\/\/stackoverflow.com\/questions\/4677044\/how-to-use-dylib-in-mac-os-x-c#answer-11585225<\/a><\/li>\n<\/ol>\n<p>--- EOF ---<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Mac \u4e0a\u7528\u5230\u4e00\u4e9b\u5f00\u6e90\u7684\u7a0b\u5e8f\uff0c\u7ecf\u5e38\u9700\u8981\u81ea\u5df1\u7f16\u8bd1\uff0c\u8fd9\u4e2a\u65f6\u5019\u4e00\u822c\u4f1a\u4f7f\u7528 macp &hellip;<\/p>\n<p class=\"read-more\"><a href=\"https:\/\/xujiwei.com\/blog\/2012\/12\/a-shell-script-for-fixing-library-load-path\/\">\u7ee7\u7eed\u9605\u8bfb &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[223,147,222,221],"_links":{"self":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/579"}],"collection":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/comments?post=579"}],"version-history":[{"count":0,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/posts\/579\/revisions"}],"wp:attachment":[{"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/media?parent=579"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/categories?post=579"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xujiwei.com\/blog\/wp-json\/wp\/v2\/tags?post=579"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}