{"id":282608,"date":"2023-09-13T04:03:07","date_gmt":"2023-09-12T20:03:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/czddsyff.html"},"modified":"2023-09-13T04:03:07","modified_gmt":"2023-09-12T20:03:07","slug":"czddsyff","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/czddsyff.html","title":{"rendered":"C\/C++\u4e2d\u7684dlopenAPI\u4f7f\u7528\u65b9\u6cd5"},"content":{"rendered":"

\u6587\u4e2d\u662flinux\u4e0bC++\u52a8\u6001\u5e93\u5b9e\u73b0\u63d2\u53e3\u63d0\u4f9b\u7c7b\u5bfc\u5165\u7684\u4e00\u4e2a\u53cd\u4f8b\u6ce8\u610f\u5176\u4e2d\u4f7f\u7528\u51fd\u6570\u8fd4\u56de\u5b50\u7c7b\u8868\u9488\u7684\u7528\u6cd5\uff0c\u7531\u4e8eLinux<\/a>\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u4e0d\u80fd\u50cfMFC\u4e2d\u90a3\u6837\u76f4\u63a5\u5bfc\u5165\u7c7b\u4e00\u3001\u4ecb\u7ecd\u600e\u6837\u4f7f\u7528dlopenAPI\u52a8\u6001\u5730\u52a0\u8f7dC++\u51fd\u6570\u548c\u7c7blinux\u67e5\u770bpthread\u5e93\u7248\u672c<\/strong>\uff0c\u662fUnixC++\u7a0b\u5e8f\u5458\u5e38\u5e38\u9047\u5230\u7684\u95ee\u9898\u3002\u4e8b\u5b9e\u4e0a\uff0c\u60c5\u51b5\u65f6\u5e38\u6709\u4e9b\u590d\u6742\uff0c\u987b\u8981\u4e00\u4e9b\u89e3\u91ca\u3002\u8fd9\u6b63\u662f\u5199\u8fd9\u7bc7miniHOWTO\u7684\u539f\u56e0\u3002\u7406\u89e3\u8fd9\u7bc7\u6587\u6863\u7684\u524d\u63d0\u662f\u5bf9C\/C++\u8bed\u8a00\u4e2ddlopenAPI\u6709\u57fa\u672c\u7684\u4e86\u89e3\u3002\u8fd9\u7bc7HOWTO\u7684\u7ef4\u62a4\u94fe\u63a5\u662f:++-dlopen-mini-HOWTO\/\u4e8c\u3001\u95ee\u9898\u6240\u5728\u6709\u65f6\u4f60\u60f3\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u4e00\u4e2a\u5e93\uff08\u5e76\u4f7f\u7528\u5176\u4e2d\u7684\u51fd\u6570\uff09\uff0c\u8fd9\u5728\u4f60\u4e3a\u4f60\u7684\u7a0b\u5e8f\u5199\u4e00\u4e9b\u63d2\u4ef6\u6216\u6a21\u5757\u6784\u67b6\u7684\u65f6\u4faf\u65f6\u5e38\u53d1\u751f\u3002\u5728C\u8bed\u8a00\u4e2d\uff0c\u52a0\u8f7d\u4e00\u4e2a\u5e93\u8f7b\u800c\u6613\u4e3e\uff08\u8c03\u7528dlopen\u3001dlsym\u548cdlclose\u5c31\u591f\u4e86\uff09\uff0c\u4f46\u5bf9C++\u6765\u8bf4\uff0c\u60c5\u51b5\u7a0d\u7a0d\u590d\u6742\u3002\u52a8\u6001\u52a0\u8f7d\u4e00\u4e2aC++\u5e93\u7684\u56f0\u96be\u4e00\u90e8\u4efd\u662f\u7531\u4e8eC++\u7684namemangling\uff08\u8bd1\u8005\u6ce8\uff1a\u4e5f\u6709\u4eba\u628a\u5b83\u7ffb\u8bd1\u4e3a\u201c\u540d\u5b57\u635f\u574f\u201d\uff0c\u6211\u8ba4\u4e3a\u8fd8\u662f\u4e0d\u7ffb\u8bd1\u597d\uff09\uff0c\u53e6\u4e00\u90e8\u4efd\u662f\u7531\u4e8edlopenAPI\u662f\u7528C\u8bed\u8a00\u5b9e\u73b0\u7684\uff0c\u56e0\u6b64\u6ca1\u6709\u63d0\u4f9b\u4e00\u4e2a\u5408\u9002\u7684\u65b9\u6cd5\u6765\u88c5\u8f7d\u7c7b\u3002\u5728\u89e3\u91ca\u600e\u6837\u88c5\u8f7dC++\u5e93\u4e4b\u524d\uff0c\u6700\u597d\u518d\u8be6\u5c3d\u4e86\u89e3\u4e00\u4e0bnamemangling\u3002<\/p>\n

\u6211\u63a8\u8350\u60a8\u4e86\u89e3\u4e00\u4e0b\u5b83\uff0c\u867d\u7136\u60a8\u5bf9\u5b83\u4e0d\u611f\u5174\u8da3\u3002\u7531\u4e8e\u8fd9\u6709\u52a9\u4e8e\u60a8\u7406\u89e3\u95ee\u9898\u662f\u600e\u6837\u5f62\u6210\u7684\uff0c\u600e\u4e48\u80fd\u591f\u89e3\u51b3\u5b83\u4eec\u30021.NameMangling\u5728\u6bcf\u4f4dC++\u7a0b\u5e8f\uff08\u6216\u5e93\u3001\u76ee\u6807\u6587\u4ef6\uff09\u4e2dlinux vi\uff0c\u6240\u6709\u975e\u9759\u6001\uff08non-static\uff09\u51fd\u6570\u5728\u4e8c\u8865\u7801\u6587\u4ef6\u4e2d\u90fd\u662f\u4ee5\u201c\u7b26\u53f7\uff08symbol\uff09\u201d\u5f62\u5f0f\u51fa\u73b0\u7684\u3002\u90a3\u4e9b\u7b26\u53f7\u90fd\u662f\u60df\u4e00\u7684\u5b57\u7b26\u4e32\uff0c\u56e0\u800c\u628a\u5404\u4e2a\u51fd\u6570\u5728\u7a0b\u5e8f\u3001\u5e93\u3001\u76ee\u6807\u6587\u4ef6\u4e2d\u533a\u5206\u5f00\u6765\u3002\u5728C\u4e2d\uff0c\u7b26\u53f7\u540d\u6b63\u662f\u51fd\u6570\u540d\uff1astrcpy\u51fd\u6570\u7684\u7b26\u53f7\u540d\u5c31\u662f\u201cstrcpy\u201d\uff0c\u7b49\u7b49\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u4e24\u4e2a\u975e\u9759\u6001\u51fd\u6570\u7684\u540d\u5b50\u4e00\u5b9a\u5404\u4e0d\u76f8\u540c\u7684\u7f18\u6545\u3002\u800cC++\u5bb9\u8bb8\u91cd\u8f7d\uff08\u4e0d\u540c\u7684\u51fd\u6570\u6709\u76f8\u540c\u7684\u540d\u5b50\u4f46\u4e0d\u540c\u7684\u53c2\u6570\uff09\uff0c\u800c\u4e14\u6709\u597d\u591aC\u6240\u6ca1\u6709\u7684\u7279\u70b9\u2500\u2500\u4f8b\u5982\u7c7b\u3001\u6210\u5458\u51fd\u6570\u3001\u5f02\u5e38\u8bf4\u660e\u2500\u2500\u51e0\u4e4e\u4e0d\u53ef\u80fd\u76f4\u63a5\u7528\u51fd\u6570\u540d\u4f5c\u7b26\u53f7\u540d\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0cC++\u91c7\u7528\u4e86\u6240\u8c13\u7684namemangling\u3002\u5b83\u628a\u51fd\u6570\u540d\u548c\u4e00\u4e9b\u4fe1\u606f\uff08\u5982\u53c2\u6570\u6570\u76ee\u548c\u5927\u5c0f\uff09\u63c9\u5408\u5728\u4e00\u8d77\uff0c\u6539\u5bfc\u81f4\u5947\u5f62\u602a\u72b6linux\u7248qq\uff0c\u53ea\u6709\u7f16\u8bd1\u5668\u624d\u61c2\u7684\u7b26\u53f7\u540d\u3002\u8bf8\u5982\uff0c\u88abmangle\u540e\u7684foo\u53ef\u80fd\u770b\u4e0a\u53bb\u50cffoo@4%6^\uff0c\u6216\u5219\uff0c\u7b26\u53f7\u540d\u91cc\u5934\u751a\u81f3\u4e0d\u5305\u62ec\u201cfoo\u201d\u3002\u5176\u4e2d\u4e00\u4e2a\u95ee\u9898\u662f\uff0cC++\u6807\u51c6\uff08\u76ee\u524d\u662f[ISO14882]\uff09\u5e76\u6ca1\u6709\u5b9a\u4e49\u540d\u5b50\u5fc5\u987b\u600e\u6837\u88abmangle\uff0c\u6240\u4ee5\u6bcf\u4f4d\u7f16\u8bd1\u5668\u90fd\u6309\u81ea\u5df1\u7684\u65b9\u6cd5\u6765\u8fdb\u884cnamemangling\u3002<\/p>\n

\u6709\u4e9b\u7f16\u8bd1\u5668\u751a\u81f3\u5728\u4e0d\u540c\u7248\u672c\u95f4\u66f4\u6362mangling\u7b97\u6cd5\uff08\u5c24\u5176\u662fg++2.x\u548c3.x\uff09\u3002\u867d\u7136\u60a8\u5398\u6e05\u695a\u4e86\u60a8\u7684\u7f16\u8bd1\u5668\u7a76\u7adf\u5982\u4f55\u8fdb\u884cmangling\u7684\uff0c\u56e0\u800c\u53ef\u4ee5\u7528dlsym\u8c03\u7528\u51fd\u6570\u4e86\uff0c\u4f46\u53ef\u80fd\u4ec5\u4ec5\u9650\u4e8e\u60a8\u624b\u5934\u7684\u8fd9\u4e2a\u7f16\u8bd1\u5668\u800c\u5df2\uff0c\u800c\u672a\u80fd\u5728\u4e0b\u4e00\u7248\u7f16\u8bd1\u5668\u4e0b\u5de5\u4f5c\u3002\u4e09\u3001\u7c7b\u4f7f\u7528dlopenAPI\u7684\u53e6\u4e00\u4e2a\u95ee\u9898\u662f\uff0c\u5b83\u53ea\u652f\u6301\u52a0\u8f7d\u51fd\u6570\u3002\u4f46\u5728C++\u4e2dlinux\u67e5\u770bpthread\u5e93\u7248\u672c<\/strong>\uff0c\u60a8\u53ef\u80fd\u8981\u7528\u5230\u5e93\u4e2d\u7684\u4e00\u4e2a\u7c7b\uff0c\u800c\u8fd9\u987b\u8981\u521b\u5efa\u8be5\u7c7b\u7684\u4e00\u4e2a\u5b9e\u4f8b\uff0c\u8fd9\u4e0d\u5bb9\u6613\u505a\u5230\u3002\u56db\u3001\u89e3\u51b3\u65b9\u68481.extern\"C\"C++\u6709\u4e2a\u7279\u5b9a\u7684\u5173\u952e\u5b57\u62ff\u6765\u7533\u660e\u91c7\u7528Cbinding\u7684\u51fd\u6570\uff1aextern\"C\"\u3002\u7528extern\"C\"\u7533\u660e\u7684\u51fd\u6570\u5c06\u4f7f\u7528\u51fd\u6570\u540d\u4f5c\u7b26\u53f7\u540d\uff0c\u5982\u540cC\u51fd\u6570\u4e00\u6837\u3002\u4e3a\u6b64\uff0c\u53ea\u6709\u975e\u6210\u5458\u51fd\u6570\u80fd\u591f\u88ab\u7533\u660e\u4e3aextern\"C\"\uff0c\u4f46\u662f\u4e0d\u80fd\u88ab\u91cd\u8f7d\u3002\u867d\u7136\u9650\u5236\u591a\u591a\uff0cextern\"C\"\u51fd\u6570\u8fd8\u662f\u5341\u5206\u6709\u7528\uff0c\u7531\u4e8e\u5b83\u4eec\u53ef\u4ee5\u8c61C\u51fd\u6570\u4e00\u6837\u88abdlopen\u52a8\u6001\u52a0\u8f7d\u3002\u51a0\u4ee5extern\"C\"\u9650\u5b9a\u7b26\u540e\uff0c\u5e76\u4e0d\u610f\u5473\u7740\u51fd\u6570\u4e2d\u96be\u4ee5\u4f7f\u7528C++\u4ee3\u7801\u4e86\uff0c\u76f8\u53cd\uff0c\u5b83\u4f9d\u7136\u662f\u4e00\u4e2a\u5b8c\u5168\u7684C++\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55C++\u7279\u70b9\u548c\u5404\u79cd\u7c7b\u578b\u7684\u53c2\u6570\u3002<\/p>\n

\u600e\u4e48\u67e5\u770b\u542f\u660e\u661f\u8fb0\u7279\u5f81\u5e93\u7248\u672c_linux\u67e5\u770bpthread\u5e93\u7248\u672c<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e8c\u3001\u95ee\u9898\u6240\u5728\u6709\u65f6\u4f60\u60f3\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u4e00\u4e2a\u5e93\uff08\u5e76\u4f7f\u7528\u5176\u4e2d\u7684\u51fd\u6570\uff09\uff0c\u8fd9\u5728\u4f60\u4e3a\u4f60\u7684\u7a0b\u5e8f\u5199\u4e00\u4e9b\u63d2\u4ef6\u6216\u6a21\u5757\u67b6\u6784\u7684\u65f6\u5019\u7ecf\u5e38\u53d1\u751f\u3002Mangling\u5728\u6bcf\u4e2aC++\u7a0b\u5e8f\uff08\u6216\u5e93\u3001\u76ee\u6807\u6587\u4ef6\uff09\u4e2d\uff0c\u6240\u6709\u975e\u9759\u6001\uff08non-static\uff09\u51fd\u6570\u5728\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u90fd\u662f\u4ee5\u201c\u7b26\u53f7\uff08symbol\uff09\u201d\u5f62\u5f0f\u51fa\u73b0\u7684\u3002C\u51fd\u6570\u8fd8\u662f\u975e\u5e38\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u8c61C\u51fd\u6570\u4e00\u6837\u88abdlopen\u52a8\u6001\u52a0\u8f7d\u3002<\/p>\n","protected":false},"author":1,"featured_media":282609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-282608","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=282608"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/282608\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/282609"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=282608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=282608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=282608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}