{"id":269,"date":"2011-12-08T17:36:54","date_gmt":"2011-12-08T09:36:54","guid":{"rendered":"http:\/\/ykyi.net\/?p=269"},"modified":"2011-12-08T17:36:54","modified_gmt":"2011-12-08T09:36:54","slug":"linux%e7%9a%84soname%ef%bc%8c%e9%93%be%e6%8e%a5%e5%ba%93%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/ykyi.net\/?p=269","title":{"rendered":"linux\u7684soname\uff0c\u94fe\u63a5\u5e93\u7684\u95ee\u9898."},"content":{"rendered":"<p><span style=\"font-size:14px;\">\u7b2c\u4e00\u6b21\u770b\u5230soname\u662f\u8bfb&lt;\u7a0b\u5e8f\u5458\u7684\u81ea\u6211\u4fee\u517b.\u7b2c\u4e00\u518c:\u94fe\u63a5\u5e93&gt;\u770b\u6765\u7684\u3002\u987a\u4fbf\u8bf4\u4e00\u4e0b\uff0c\u8fd9\u672c\u4e66\u786e\u5b9e\u662f\u672c\u597d\u4e66\u5416\uff0c\u56fd\u5185\u51fa\u7684\u96be\u5f97\u6280\u672f\u597d\u4e66\u3002\u540e\u6765\u5728\u516c\u53f8\u7684\u9879\u76ee\u4e2d\u628a\u5b83\u4ecewindows\u5e73\u53f0\u4e0b\u79fb\u690d\u5230linux\u4e0b\uff0c\u5199makefile\u65f6\u7528\u5230\u8fc7\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\">\u518d\u540e\u6765\u53c8\u5fd8\u8bb0\u4e86\u3002\u4eca\u5929\u518d\u6b21\u770b\u5230soname\u7684\u65f6\u5019\u5c31\u6709\u70b9\u8bb0\u4e0d\u8d77\u6765\u4e86\u3002\u53c8\u53ea\u597d\u641c\u7d22\u4e86\u4e00\u4e9b\u8d44\u6599\u770b\u3002\u8d81\u70ed\u6253\u94c1\u628a\u5b66\u4f1a\u7684\u4e1c\u897f\u8bb0\u4e0b\u6765\u3002<\/span><\/p>\n<p><span style=\"font-size:14px;\">linux\u4e3a\u5c1d\u8bd5\u89e3\u51b3\u52a8\u6001\u94fe\u63a5\u5e93\u7248\u672c\u51b2\u7a81\u7684\u95ee\u9898(windows\u5e73\u53f0\u4e0b\u79f0\u4e4b\u4e3aDLL HELL)\uff0c\u5f15\u5165\u4e86soname\u8fdb\u5236\u3002linux\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u6269\u5c55\u540d\u7ea6\u5b9a\u4e3a.so \u5373shared object\u7684\u7f29\u5199\u3002\u4e0b\u9762\u7684makefile\u8bed\u53e5\u6765\u81ea\u4e8e\u54e5\u4eca\u5e74\u4e0a\u534a\u5e74\u5199\u7684makefile\u6587\u4ef6:<\/span><\/p>\n<p><span style=\"font-size:14px;\"><span style=\"color: rgb(0, 0, 255); \">VERSION_NUM := 1.0.0<\/span><br \/>\n    soname = lib<span class=\"katex math inline\">(dirname).so.<\/span>(firstword <span class=\"katex math inline\">(subst ., ,<\/span>(VERSION_NUM)))<br \/>\n    LINKFLAGS := -shared -Wl,-soname,$(soname) -L. -lpthread -lrt -lpentagon -lcross_platform<br \/>\n    \u5176\u4e2d\u7684\u53d8\u91cf$(soname)\u4f1a\u88ab\u66ff\u6362\u4e3aeibcomm.so.1\u3002\u518d\u770b\u770bLINKFLAGS\u53d8\u91cf\u6307\u5b9a\u7684\u51e0\u4e2a\u9009\u9879. -shared \u8868\u793a\u8981\u751f\u6210\u4e00\u4e2ashared object\uff0c\u5373\u52a8\u6001\u5171\u4eab\u5e93. -pthread -lrt -lpentagon -lcross_platform \u662f\u8981\u94fe\u63a5\u5176\u5b83\u51e0\u4e2a\u5e93\uff0cthread\u548clinux\u7684posix\u7ebf\u7a0b\u5e93,rt\u662f\u4e00\u4e2a\u548c\u5b9e\u65f6\u7cfb\u7edf\u76f8\u5173\u7684\u5e93\u5b83\u63d0\u4f9b\u4e86\u9ad8\u7cbe\u5ea6\u7684\u65f6\u95f4\u51fd\u6570\u3002<\/span><\/p>\n<p><span style=\"font-size:14px;\">\u6bd4\u8f83\u5947\u602a\u7684\u662f -Wl,-soname,$(soname) \u5b83\u4eec\u4e4b\u524d\u7528\u9017\u53f7\u5206\u5f00\uff0c\u800c\u4e0d\u662f\u7528\u7a7a\u683c\u5206\u5f00\u3002\u5b9e\u9645\u4e0a\u8fd9\u51e0\u4e2a\u4e1c\u4e1c\u4f1a\u88abgcc\u4f20\u7ed9ld(linux\u4e0b\u7684\u94fe\u63a5\u5668)\u4f5c\u4e3a\u94fe\u63a5\u5668\u7684\u53c2\u6570\u3002gcc\u89c4\u5b9a\u7684\u5199\u6cd5\u5c31\u662f\u8fd9\u6837\u7684\u3002\u6307\u5b9a\u7684soname\u4f1a\u88ab\u94fe\u63a5\u5668\u5199\u5165\u5230\u6700\u7ec8\u751f\u6210\u7684elf\u6587\u4ef6\u4e2d(linux\u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f)\u3002\u8981\u67e5\u770belf\u6587\u4ef6\u7684\u6bb5\u5e03\u5c40\u4ec0\u4e48\u7684\uff0c\u53ef\u4ee5\u7528readelf\u5de5\u5177\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size:14px;\">\u6700\u7ec8\u751f\u6210\u7684\u6587\u4ef6\u5c06\u547d\u540d\u4e3a libname.so.x.y.z \u7684\u5f62\u5f0f\u3002soname\u662flibname.so.x\u7684\u683c\u5f0f(\u4e5f\u4e0d\u5c3d\u7136\uff0c\u8fd9\u53ea\u662f\u4e00\u4e2aconvetion,\u5e76\u975e\u5728\u8bed\u6cd5\u6216\u673a\u5236\u4e0a\u5f3a\u884c\u8981\u6c42)\u3002\u63a5\u7740\u628a\u751f\u6210\u7684so\u6587\u4ef6\u62f7\u8d1d\u5230\/usr\/lib \u6216\u8005 \/lib\uff0c\u8fd9\u4e24\u4e2a\u6587\u4ef6\u5939\u662f\u7cfb\u7edf\u7528\u6765\u653e\u7f6e\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u5730\u65b9\u3002debian\u4e0b\u6ca1\u6709\u628a\/usr\/local\/lib\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u6587\u4ef6\u5939.\u53ef\u4ee5\u901a\u8fc7\u6539\/etc\/ld.so.conf \u6587\u4ef6\u628a\u66f4\u591a\u7684\u8def\u5f84\u52a0\u5165\u3002\u518d\u8fd0\u884c ldconfig,\u66f4\u65b0cache\u4e2d\u7684\u5e93\u6587\u4ef6\u4fe1\u606f\u3002\u4e3a\u4ec0\u4e48\u8981\u7528cache\u5462\uff0c\u6709\u4eba\u5c31\u95ee\u4e86\uff01\u56e0\u4e3alibrary\u5b9e\u5728\u592a\u591a\u4e86\u54af\uff0ccache\u5c31\u88ab\u5f15\u7528\u4e86\u3002cache\u662f\u4e2a\u597d\u4e1c\u897f\u554a\uff01\uff01\uff01<\/span><\/p>\n<p><span style=\"font-size:14px;\">\u8fd9\u4e2a\u65f6\u5019\u4f9d\u8d56 libname.so.x \u7684\u6587\u4ef6\u5c31\u53ef\u4ee5\u627e\u5230\u8fd9\u4e2alibrary\u5e76\u52a0\u8f7d\u8d77\u6765\u4e86\u3002\u4f46\u662f\u7f16\u8bd1\u7a0b\u5e8f\u65f6\u8fd8\u662f\u627e\u4e0d\u5230\u5462.\u7f16\u8bd1\u7a0b\u5e8f\u65f6\u901a\u5e38\u4f1a\u5199 -lname \u8fd9\u4e2a\u65f6\u5019\u4f1a\u5148\u627e libname.so \u518d\u627e libname.a \u6587\u4ef6\uff0c\u7ed3\u679c\u627e\u4e0d\u5230\u3002link\u5c31\u4f1a\u62b1\u6028\u6ca1\u6709\u627e\u5230\u8fd9\u4e2a\u5e93\u6587\u4ef6\u3002\u4e3a\u4e86\u8ba9\u7f16\u8bd1\u901a\u8fc7\uff0c\u4e8e\u662f\u4f60\u5c31\u7528 ln -sf libname.so libname.so.x.y.z (\u8fd9\u4e2a\u662frealname,\u7248\u672c\u53f7\u90e8\u5206\u53ef\u80fd\u53ea\u6709x.y\u4e24\u4e2a\u90e8\u5206) \u5efa\u4e00\u4e2a\u8f6f\u94fe\u63a5\uff01\u641e\u5b9a\uff01<\/span><\/p>\n<p><span style=\"font-size:14px;\">copyright ykyi.net<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e00\u6b21\u770b\u5230soname\u662f\u8bfb&lt;\u7a0b\u5e8f\u5458\u7684\u81ea\u6211\u4fee\u517b.\u7b2c\u4e00\u518c:\u94fe\u63a5\u5e93&gt;\u770b\u6765\u7684\u3002\u987a\u4fbf\u8bf4\u4e00\u4e0b\uff0c\u8fd9\u672c\u4e66\u786e\u5b9e\u662f\u672c\u597d\u4e66\u5416\uff0c\u56fd\u5185\u51fa\u7684\u96be\u5f97\u6280\u672f\u597d\u4e66\u3002\u540e\u6765\u5728\u516c\u53f8\u7684\u9879\u76ee\u4e2d\u628a\u5b83\u4ecewindows\u5e73\u53f0\u4e0b\u79fb\u690d\u5230linux\u4e0b\uff0c\u5199makefile\u65f6\u7528\u5230\u8fc7\u3002 &nbsp; \u518d\u540e\u6765\u53c8\u5fd8\u8bb0\u4e86\u3002\u4eca\u5929\u518d\u6b21\u770b\u5230soname\u7684\u65f6\u5019\u5c31\u6709\u70b9\u8bb0\u4e0d\u8d77\u6765\u4e86\u3002\u53c8\u53ea\u597d\u641c\u7d22\u4e86\u4e00\u4e9b\u8d44\u6599\u770b\u3002\u8d81\u70ed\u6253\u94c1\u628a\u5b66\u4f1a\u7684\u4e1c\u897f\u8bb0\u4e0b\u6765\u3002 linux\u4e3a\u5c1d\u8bd5\u89e3\u51b3\u52a8\u6001\u94fe\u63a5\u5e93\u7248\u672c\u51b2\u7a81\u7684\u95ee\u9898(windows\u5e73\u53f0\u4e0b\u79f0\u4e4b\u4e3aDLL HELL)\uff0c\u5f15\u5165\u4e86soname\u8fdb\u5236\u3002linux\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u6269\u5c55\u540d\u7ea6\u5b9a\u4e3a.so \u5373shared object\u7684\u7f29\u5199\u3002\u4e0b\u9762\u7684makefile\u8bed\u53e5\u6765\u81ea\u4e8e\u54e5\u4eca\u5e74\u4e0a\u534a\u5e74\u5199\u7684makefile\u6587\u4ef6: VERSION_NUM := 1.0.0 soname = lib(dirname).so.(firstword (subst ., ,(VERSION_NUM))) LINKFLAGS := -shared -Wl,-soname,$(soname) -L. -lpthread -lrt -lpentagon -lcross_platform \u5176\u4e2d\u7684\u53d8\u91cf$(soname)\u4f1a\u88ab\u66ff\u6362\u4e3aeibcomm.so.1\u3002\u518d\u770b\u770bLINKFLAGS\u53d8\u91cf\u6307\u5b9a\u7684\u51e0\u4e2a\u9009\u9879. -shared \u8868\u793a\u8981\u751f\u6210\u4e00\u4e2ashared object\uff0c\u5373\u52a8\u6001\u5171\u4eab\u5e93. -pthread -lrt -lpentagon -lcross_platform \u662f\u8981\u94fe\u63a5\u5176\u5b83\u51e0\u4e2a\u5e93\uff0cthread\u548clinux\u7684posix\u7ebf\u7a0b\u5e93,rt\u662f\u4e00\u4e2a\u548c\u5b9e\u65f6\u7cfb\u7edf\u76f8\u5173\u7684\u5e93\u5b83\u63d0\u4f9b\u4e86\u9ad8\u7cbe\u5ea6\u7684\u65f6\u95f4\u51fd\u6570\u3002 \u6bd4\u8f83\u5947\u602a\u7684\u662f -Wl,-soname,$(soname) \u5b83\u4eec\u4e4b\u524d\u7528\u9017\u53f7\u5206\u5f00\uff0c\u800c\u4e0d\u662f\u7528\u7a7a\u683c\u5206\u5f00\u3002\u5b9e\u9645\u4e0a\u8fd9\u51e0\u4e2a\u4e1c\u4e1c\u4f1a\u88abgcc\u4f20\u7ed9ld(linux\u4e0b\u7684\u94fe\u63a5\u5668)\u4f5c\u4e3a\u94fe\u63a5\u5668\u7684\u53c2\u6570\u3002gcc\u89c4\u5b9a\u7684\u5199\u6cd5\u5c31\u662f\u8fd9\u6837\u7684\u3002\u6307\u5b9a\u7684soname\u4f1a\u88ab\u94fe\u63a5\u5668\u5199\u5165\u5230\u6700\u7ec8\u751f\u6210\u7684elf\u6587\u4ef6\u4e2d(linux\u4e0b\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f)\u3002\u8981\u67e5\u770belf\u6587\u4ef6\u7684\u6bb5\u5e03\u5c40\u4ec0\u4e48\u7684\uff0c\u53ef\u4ee5\u7528readelf\u5de5\u5177\u3002 &nbsp; \u6700\u7ec8\u751f\u6210\u7684\u6587\u4ef6\u5c06\u547d\u540d\u4e3a libname.so.x.y.z \u7684\u5f62\u5f0f\u3002soname\u662flibname.so.x\u7684\u683c\u5f0f(\u4e5f\u4e0d\u5c3d\u7136\uff0c\u8fd9\u53ea\u662f\u4e00\u4e2aconvetion,\u5e76\u975e\u5728\u8bed\u6cd5\u6216\u673a\u5236\u4e0a\u5f3a\u884c\u8981\u6c42)\u3002\u63a5\u7740\u628a\u751f\u6210\u7684so\u6587\u4ef6\u62f7\u8d1d\u5230\/usr\/lib \u6216\u8005 \/lib\uff0c\u8fd9\u4e24\u4e2a\u6587\u4ef6\u5939\u662f\u7cfb\u7edf\u7528\u6765\u653e\u7f6e\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u5730\u65b9\u3002debian\u4e0b\u6ca1\u6709\u628a\/usr\/local\/lib\u4f5c\u4e3a\u9ed8\u8ba4\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u6587\u4ef6\u5939.\u53ef\u4ee5\u901a\u8fc7\u6539\/etc\/ld.so.conf \u6587\u4ef6\u628a\u66f4\u591a\u7684\u8def\u5f84\u52a0\u5165\u3002\u518d\u8fd0\u884c ldconfig,\u66f4\u65b0cache\u4e2d\u7684\u5e93\u6587\u4ef6\u4fe1\u606f\u3002\u4e3a\u4ec0\u4e48\u8981\u7528cache\u5462\uff0c\u6709\u4eba\u5c31\u95ee\u4e86\uff01\u56e0\u4e3alibrary\u5b9e\u5728\u592a\u591a\u4e86\u54af\uff0ccache\u5c31\u88ab\u5f15\u7528\u4e86\u3002cache\u662f\u4e2a\u597d\u4e1c\u897f\u554a\uff01\uff01\uff01 \u8fd9\u4e2a\u65f6\u5019\u4f9d\u8d56 libname.so.x \u7684\u6587\u4ef6\u5c31\u53ef\u4ee5\u627e\u5230\u8fd9\u4e2alibrary\u5e76\u52a0\u8f7d\u8d77\u6765\u4e86\u3002\u4f46\u662f\u7f16\u8bd1\u7a0b\u5e8f\u65f6\u8fd8\u662f\u627e\u4e0d\u5230\u5462.\u7f16\u8bd1\u7a0b\u5e8f\u65f6\u901a\u5e38\u4f1a\u5199 -lname \u8fd9\u4e2a\u65f6\u5019\u4f1a\u5148\u627e libname.so \u518d\u627e libname.a \u6587\u4ef6\uff0c\u7ed3\u679c\u627e\u4e0d\u5230\u3002link\u5c31\u4f1a\u62b1\u6028\u6ca1\u6709\u627e\u5230\u8fd9\u4e2a\u5e93\u6587\u4ef6\u3002\u4e3a\u4e86\u8ba9\u7f16\u8bd1\u901a\u8fc7\uff0c\u4e8e\u662f\u4f60\u5c31\u7528 ln &hellip; <a href=\"https:\/\/ykyi.net\/?p=269\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;linux\u7684soname\uff0c\u94fe\u63a5\u5e93\u7684\u95ee\u9898.&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[34,51,55,73],"class_list":["post-269","post","type-post","status-publish","format-standard","hentry","category-tech_articles","category-unix_linux","tag-gcc","tag-linux-2","tag-makefile","tag-soname"],"_links":{"self":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=269"}],"version-history":[{"count":0,"href":"https:\/\/ykyi.net\/index.php?rest_route=\/wp\/v2\/posts\/269\/revisions"}],"wp:attachment":[{"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ykyi.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}