{"id":930,"date":"2024-02-23T14:25:19","date_gmt":"2024-02-23T06:25:19","guid":{"rendered":"http:\/\/blog.chxzking.cn\/?p=930"},"modified":"2024-02-24T21:39:57","modified_gmt":"2024-02-24T13:39:57","slug":"linux%e4%b8%8b%e7%9a%84c%e5%8a%a8%e6%80%81%e5%ba%93","status":"publish","type":"post","link":"http:\/\/blog.chxzking.cn\/index.php\/2024\/02\/23\/linux%e4%b8%8b%e7%9a%84c%e5%8a%a8%e6%80%81%e5%ba%93\/","title":{"rendered":"Linux\u4e0b\u7684\u52a8\u6001\u5e93\u4e0e\u9759\u6001\u5e93"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><kbd>\u9759\u6001\u5e93(Static Link Library)<\/kbd><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u9759\u6001\u5e93\u7684\u6982\u5ff5\u548c\u4f5c\u7528<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u9759\u6001\u5e93\u7684\u6982\u5ff5<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u9759\u6001\u5e93<\/mark>\u662f\u4e00\u79cd\u5305\u542b\u4e86\u591a\u4e2a\u5bf9\u8c61\u6587\u4ef6\uff08object file\uff09\u7684\u6587\u4ef6\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u6587\u4ef6\u5728\u94fe\u63a5\u9636\u6bb5\u4f1a\u88ab\u6574\u5408\u5230\u6700\u7ec8\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u9759\u6001\u5e93\u7684\u6587\u4ef6\u6269\u5c55\u540d\u901a\u5e38\u4e3a\u00a0<code>.a<\/code>\uff08\u5728Unix-like\u7cfb\u7edf\u4e2d\uff09\u6216\u00a0<code>.lib<\/code>\uff08\u5728Windows\u7cfb\u7edf\u4e2d\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728c\u6587\u4ef6\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u65f6\u4f1a\u7ecf\u8fc7\u56db\u4e2a\u9636\u6bb5\u2014\u2014\u9884\u5904\u7406<code>(.c)<\/code>\u3001\u7f16\u8bd1<code>(.s)<\/code>\u3001\u6c47\u7f16<code>(.o)<\/code>\u3001\u94fe\u63a5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u800c\u9759\u6001\u5e93\u6587\u4ef6\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u76ee\u6807\u6587\u4ef6<code>(.o)<\/code>\u3002\u5728\u94fe\u63a5\u9636\u6bb5\u548c\u6240\u6709\u7684\u76ee\u6807\u6587\u4ef6\u8fdb\u884c\u6574\u5408\u3001\u94fe\u63a5\uff0c\u6700\u540e\u751f\u6210\u4e86\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u5f80\u5f80\u4e0d\u4f1a\u5c06\u9759\u6001\u5e93\u76f4\u63a5\u505a\u6210\u4e00\u4e2a<code>.o<\/code>\u6587\u4ef6\uff0c\u800c\u662f\u4f1a\u901a\u8fc7\u5176\u4ed6\u547d\u4ee4\uff0c\u751f\u6210\u4e00\u4e2a<code>.a<\/code>\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3b\u8981\u539f\u56e0\u6709\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u65b9\u4fbf\u7ba1\u7406<\/strong>\uff1a\u5728\u5927\u578b\u5f00\u53d1\u4e2d\uff0c\u4e00\u4e2a\u9759\u6001\u5e93\u5f80\u5f80\u7531\u4f17\u591a\u6570\u91cf\u7684.o\u6587\u4ef6\u6784\u6210\uff0c\u5982\u679c\u4ec5\u4ec5\u4f7f\u7528.o\u6587\u4ef6\uff0c\u90a3\u4e48\u5c06\u4f1a\u975e\u5e38\u6df7\u4e71\u3002<\/li>\n\n\n\n<li><strong>\u63d0\u9ad8\u7f16\u8bd1\u6548\u7387<\/strong>\uff1a\u591a\u4e2a.o\u6587\u4ef6\u5728\u7a0b\u5e8f\u94fe\u63a5\u8fc7\u7a0b\u4e2d\u662f\u975e\u5e38\u5f71\u54cd\u6548\u7387\uff0c\u6240\u4ee5\u5c06\u8fd9\u4e9b\u6587\u4ef6\u6574\u5408\u7f16\u8bd1\u6210\u4e00\u4e2a.a\u6587\u4ef6\uff0c\u8f6f\u4ef6\u7f16\u8bd1\u7684\u94fe\u63a5\u9636\u6bb5\u5219\u53ea\u9700\u8981\u94fe\u63a5\u8fd9\u4e00\u4e2a\u5e93\u5373\u53ef\u3002<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u6027<\/strong>\uff1a.a\u6587\u4ef6\u65b9\u4fbf\u8fdb\u884c\u6743\u9650\u8bbe\u7f6e\uff0c\u9650\u5236\u5bf9\u4ee3\u7801\u7684\u4fee\u6539\u6216\u8005\u76d7\u7528<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u9759\u6001\u5e93\u7684\u4f18\u7f3a\u70b9\uff1a<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u5e93\u7684\u4f18\u70b9\u6709\u5982\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4ee3\u7801\u590d\u7528<\/strong>\uff1a\u9759\u6001\u5e93\u53ef\u4ee5\u5305\u542b\u4e00\u4e9b\u5e38\u7528\u7684\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u591a\u4e2a\u7a0b\u5e8f\u4e2d\u590d\u7528\u8fd9\u4e9b\u4ee3\u7801\uff0c\u800c\u65e0\u9700\u6bcf\u6b21\u90fd\u91cd\u65b0\u7f16\u5199\u3002<\/li>\n\n\n\n<li><strong>\u6a21\u5757\u5316<\/strong>\uff1a\u901a\u8fc7\u5c06\u76f8\u5173\u7684\u51fd\u6570\u548c\u6570\u636e\u7ed3\u6784\u6253\u5305\u5230\u4e00\u4e2a\u9759\u6001\u5e93\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u5f97\u4ee3\u7801\u7ed3\u6784\u66f4\u6e05\u6670\uff0c\u66f4\u6613\u4e8e\u7ba1\u7406\u548c\u7ef4\u62a4\u3002<\/li>\n\n\n\n<li><strong>\u51cf\u5c11\u7f16\u8bd1\u65f6\u95f4<\/strong>\uff1a\u5f53\u9759\u6001\u5e93\u7684\u4ee3\u7801\u6ca1\u6709\u6539\u53d8\u65f6\uff0c\u94fe\u63a5\u9759\u6001\u5e93\u7684\u7a0b\u5e8f\u65e0\u9700\u91cd\u65b0\u7f16\u8bd1\u5e93\u4e2d\u7684\u4ee3\u7801\uff0c\u8fd9\u53ef\u4ee5\u5927\u5927\u51cf\u5c11\u7f16\u8bd1\u65f6\u95f4<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u5e93\u7684\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6269\u5927\u53ef\u6267\u884c\u6587\u4ef6<\/strong>\uff1a\u56e0\u4e3a\u9759\u6001\u5e93\u9700\u8981\u5c06\u6240\u6709\u7684\u4ee3\u7801\u590d\u5236\u5230\u7a0b\u5e8f\u4e2d\u5171\u540c\u7f16\u8bd1\uff0c\u6240\u4ee5\u4f1a\u589e\u5927\u6700\u7ec8\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5927\u5c0f<\/li>\n\n\n\n<li><strong>\u5360\u7528\u5185\u5b58<\/strong>\uff1a\u5982\u679c\u6709\u591a\u4e2a\u7a0b\u5e8f\u90fd\u8c03\u7528\u4e86\u540c\u4e00\u4e2a\u9759\u6001\u5e93\uff0c\u90a3\u4e48\u5728\u5185\u5b58\u4e2d\u4f9d\u65e7\u4f1a\u590d\u5236\u540c\u6837\u6570\u91cf\u7ea7\u7684\u4ee3\u7801\uff0c\u5360\u7528\u4e0d\u540c\u7684\u7a7a\u95f4\uff0c\u800c\u4e0d\u662f\u5171\u540c\u540c\u4e00\u7a7a\u95f4\u3002<\/li>\n\n\n\n<li><strong>\u66f4\u65b0\u95ee\u9898<\/strong>\uff1a\u7531\u4e8e\u9759\u6001\u5e93\u662f\u5728\u7f16\u8bd1\u6e90\u4ee3\u7801\u65f6\u53c2\u4e0e\u7f16\u8bd1\u8fc7\u7a0b\uff0c\u6240\u4ee5\u5982\u679c\u5e93\u53d1\u751f\u4e86\u5373\u4fbf\u975e\u5e38\u5fae\u5c0f\u7684\u53d8\u5316\uff0c\u4e5f\u4f1a\u5bfc\u81f4\u6574\u4e2a\u8f6f\u4ef6\u91cd\u65b0\u7f16\u8bd1\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u521b\u5efa\u9759\u6001\u5e93<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">1\u3001\u7f16\u8bd1\u6e90\u4ee3\u7801<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528<code>gcc<\/code>\u547d\u4ee4\u5c06<code>.c<\/code>\u6587\u4ef6\u7f16\u8bd1\u6210<code>.o<\/code>\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5355\u4e2a\u6587\u4ef6\u7f16\u8bd1\u6709\u4e24\u79cd\u65b9\u5f0f\uff0c\u7b2c\u4e8c\u79cd\u53ef\u4ee5\u5728-o\u540e\u9762\u81ea\u5df1\u6307\u5b9a\u540d\u79f0\ngcc -c file1.c \u6216 gcc file.c -o file.o -c\n\/\/\u591a\u4e2a\u6587\u4ef6\u7f16\u8bd1\uff0c\u591a\u6587\u4ef6\u7f16\u8bd1\u6ca1\u6709-o\u5f62\u5f0f\ngcc -c file1.c file2.c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8bd1\u4e4b\u540e\u4f1a\u5f97\u5230\u4e00\u4e2a\u6216\u8005\u591a\u4e2a<code>.o<\/code>\u6587\u4ef6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">2\u3001\u521b\u5efa\u9759\u6001\u5e93<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u4e00\u4e2a\u6216\u8005\u591a\u4e2a<code>.o<\/code>\u6587\u4ef6\u751f\u6210<code>.a<\/code>\u6587\u4ef6\u9700\u8981\u4f7f\u7528<code>ar<\/code>\u547d\u4ee4\uff08archiver \u5f52\u6863\u5668\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>ar<\/code>\u547d\u4ee4\u4e00\u822c\u8ddf\u968f\u4e09\u4e2a\u53c2\u6570<code>rcs<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>r<\/code>\uff1a\u4ee3\u8868&#8221;replace&#8221;\uff0c\u610f\u4e3a\u66ff\u6362\u3002\u5982\u679c\u9759\u6001\u5e93\u4e2d\u5df2\u7ecf\u5b58\u5728\u540c\u540d\u7684\u6210\u5458\uff0c\u90a3\u4e48\u8fd9\u4e2a\u9009\u9879\u4f1a\u7528\u65b0\u7684\u5bf9\u8c61\u6587\u4ef6\u66ff\u6362\u5b83\u3002<\/li>\n\n\n\n<li><code>c<\/code>\uff1a\u4ee3\u8868&#8221;create&#8221;\uff0c\u610f\u4e3a\u521b\u5efa\u3002\u8fd9\u4e2a\u9009\u9879\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u9759\u6001\u5e93\u3002\u5982\u679c\u9759\u6001\u5e93\u5df2\u7ecf\u5b58\u5728\uff0c\u90a3\u4e48\u8fd9\u4e2a\u9009\u9879\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55\u6548\u679c\u3002<\/li>\n\n\n\n<li><code>s<\/code>\uff1a\u4ee3\u8868&#8221;index&#8221;\uff0c\u610f\u4e3a\u7d22\u5f15\u3002\u8fd9\u4e2a\u9009\u9879\u4f1a\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6587\u4ef6\u7684\u7d22\u5f15\uff0c\u4ee5\u52a0\u5feb\u94fe\u63a5\u5668\u7684\u67e5\u627e\u901f\u5ea6\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a\u5728\u9759\u6001\u5e93\u7684\u547d\u540d\u4e2d\u6709\u4e00\u4e2a\u7ea6\u5b9a\u2014\u2014<code>lib\u6587\u4ef6\u540d.a<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4--\u5047\u8bbe\u76ee\u6807\u6587\u4ef6\u4e3atemp.o\nar rcs libtemp.a temp.o\n\/\/\u591a\u6587\u4ef6\u7f16\u8bd1\nar rcs libtemp.a temp1.o temp2.o temp3.o<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">3\u3001\u8865\u5145<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9759\u6001\u5e93\u7f16\u8bd1\u5e76\u6ca1\u6709\u7c7b\u4f3cgcc\u7f16\u8bd1c\u6587\u4ef6\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u7f29\u51cf\u547d\u4ee4\uff0c\u5373\u4f7f\u7528gcc -o\u5c06\u56db\u4e2a\u6b65\u9aa4\u4e00\u6b65\u5230\u4f4d\u3002\u4f46\u662f\u53ef\u4ee5\u4f7f\u7528<code>shell<\/code>\u547d\u4ee4\u4e2d\u7684<code>&amp;&amp;<\/code>\u547d\u4ee4(\u82e5\u524d\u4e00\u4e2a\u547d\u4ee4\u6267\u884c\u6210\u529f\u5219\u6267\u884c\u540e\u4e00\u4e2a\u547d\u4ee4)\u8fdb\u884c\u7c7b\u4f3c\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u5355\u6587\u4ef6\u7f16\u8bd1\ngcc temp.c -o temp.o -c &amp;&amp; ar rcs libmytemp.a temp.o\n\/\/\u591a\u6587\u4ef6\u7f16\u8bd1\ngcc -c temp1.c temp2.c &amp;&amp; ar rcs libtemp.a temp1.o temp2.o<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u5982\u4f55\u94fe\u63a5\u9759\u6001\u5e93<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u94fe\u63a5\u7a0b\u5e8f\u65f6\u6307\u5b9a\u9759\u6001\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u5728gcc\u547d\u4ee4\u884c\u4e2d\u6dfb\u52a0<code>-L<\/code>\u9009\u9879\uff08\u7528\u4e8e\u6307\u5b9a\u5e93\u7684\u641c\u7d22\u8def\u5f84\uff0c\u65e2\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u4e5f\u53ef\u4ee5\u662f\u7edd\u5bf9\u8def\u5f84\uff09\u548c<code>-l<\/code>\u9009\u9879\uff08\u7528\u4e8e\u6307\u5b9a\u5e93\u7684\u540d\u79f0\uff09\u6765\u5b8c\u6210\u3002\u4f46\u662f\u8fd9\u4e2a\u5e93\u4e0d\u9700\u8981\u5199<code>lib<\/code>\u548c<code>.a<\/code>\u540e\u7f00<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u5373\u4fbf\u662f\u5b58\u5728\u9759\u6001\u5e93\uff0c\u4f46\u662f\u5728\u5199\u6e90\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4f9d\u7136\u9700\u8981\u5bf9\u9759\u6001\u5e93\u51fd\u6570\u8fdb\u884c\u58f0\u660e\u3002\u6240\u4ee5\u901a\u5e38\u4e00\u4e2a\u9759\u6001\u5e93\u4f1a\u5305\u542b\u4e00\u4e2a<code>.h<\/code>\u5934\u6587\u4ef6\u3002\u5728\u7f16\u5199\u6e90\u4ee3\u7801\u7684\u65f6\u5019<code>include<\/code>\u8fd9\u4e2a\u5934\u6587\u4ef6\u3002\u5982\u679c\u5934\u6587\u4ef6\u5728\u5176\u4ed6\u5730\u65b9\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>-I<\/code>\u6765\u5b9a\u4f4d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4,\u5047\u8bbe\u6709\u4e00\u4e2a\u9759\u6001\u5e93libtemp.a\ngcc main.c -o main -L.\/ -ltemp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u793a\u4f8b1\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u6709\u4e00\u4e2a\u6587\u4ef6main.c\u5176\u540c\u6587\u4ef6\u5bb6\u4e2d\u67091.h 1.c 2.h 2.c \u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/1.h\n#ifndef _1_H\n#define _1_H\n#include&lt;stdio.h&gt;\nvoid func1();\n#endif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/1.c\n#include\"1.h\"\nvoid func1(){\n    printf(\"\u8fd9\u662f1.c\\n\");\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/2.h\n#ifndef _2_H\n#define _2_H\n#include&lt;stdio.h&gt;\nvoid func2();\n#endif<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/2.c\n#include\"2.h\"\nvoid func2(){\n    printf(\"\u8fd9\u662f2.c\\n\");\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/main.c\n#include\"1.h\"\n#include\"2.h\"\nint main(){\n    func1();\n    func2();\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c061.c\u548c2.c\u7f16\u8bd1\u6210\u9759\u6001\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc -c 1.c 2.c &amp;&amp; ar rcs libtemp.a 1.o 2.o<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u5047\u8bbe\u8fd9\u4e2a\u9759\u6001\u5e93\u5728\u540c\u76ee\u5f55\u7684tempdir\u76ee\u5f55\u4e2d\uff0c\u90a3\u4e48\u5e94\u8be5\u8fd9\u6837\u94fe\u63a5libtemp.a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc main.c -o main -L.\/tempdir -ltemp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165<code>.\/main<\/code>\u8fd0\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u5f97\u5230\u8fd9\u6837\u7684\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u8fd9\u662f1.c\n\u8fd9\u662f2.c<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><kbd>\u52a8\u6001\u5e93(Dynamic Link Library)<\/kbd><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u57fa\u7840<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7684\u6982\u5ff5\u548c\u4f5c\u7528<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7684\u6982\u5ff5<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u52a8\u6001\u5e93<\/mark>\u662f\u4e00\u79cd\u5305\u542b\u4e86\u591a\u4e2a\u5bf9\u8c61\u6587\u4ef6\uff08object file\uff09\u7684\u6587\u4ef6\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u6587\u4ef6\u5728\u7a0b\u5e8f\u8fd0\u884c\u65f6\u624d\u88ab\u52a0\u8f7d\u548c\u94fe\u63a5\u5230\u7a0b\u5e8f\u4e2d\u3002\u52a8\u6001\u5e93\u7684\u6587\u4ef6\u6269\u5c55\u540d\u901a\u5e38\u4e3a\u00a0<code>.so<\/code>\uff08\u5728Unix-like\u7cfb\u7edf\u4e2d\uff09\u6216\u00a0<code>.dll<\/code>\uff08\u5728Windows\u7cfb\u7edf\u4e2d\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c\u9759\u6001\u5e93\u4e0d\u540c\u7684\u662f\uff0c\u52a8\u6001\u5e93\u53ea\u6709\u5728\u7f16\u8bd1\u6210.so\u6587\u4ef6\u540e\u624d\u80fd\u53d1\u6325\u51fa\u7279\u6709\u529f\u80fd<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8fd0\u884c\u65f6\u94fe\u63a5<\/strong>\uff1a\u7a0b\u5e8f\u94fe\u63a5\u52a8\u6001\u5e93\u662f\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\uff0c\u800c\u4e0d\u662f\u5728\u7f16\u8bd1\u9636\u6bb5\uff0c\u6240\u4ee5\u5728\u5c01\u88c5\u4e3a\u52a8\u6001\u5e93\u6587\u4ef6.so\u65f6\u624d\u80fd\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u3002<\/li>\n\n\n\n<li><strong>\u4ee3\u7801\u5171\u4eab<\/strong>\uff1a\u591a\u4e2a\u7a0b\u5e8f\u5982\u679c\u76f8\u5bf9\u540c\u4e00\u4e2a\u52a8\u6001\u5e93\u64cd\u4f5c\uff0c\u53ea\u6709\u5c01\u88c5\u6210.so\u6587\u4ef6\u624d\u80fd\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7684\u4f18\u70b9\u548c\u7f3a\u70b9<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u6001\u5e93\u7684\u4f18\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8282\u7701\u5185\u5b58\u7a7a\u95f4<\/strong>\uff1a\u52a8\u6001\u5e93\u53ef\u4ee5\u5b9e\u73b0\u540c\u4e00\u4e2a\u4ee3\u7801\u88ab\u591a\u4e2a\u7a0b\u5e8f\u8bbf\u95ee\uff0c\u800c\u975e\u5355\u72ec\u590d\u5236\u7ed9\u6bcf\u4e2a\u7a0b\u5e8f\uff0c\u5927\u5927\u51cf\u5c11\u4e86\u5185\u5b58\u5360\u7528\u3002<\/li>\n\n\n\n<li><strong>\u964d\u4f4e\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5927\u5c0f<\/strong>\uff1a\u5728\u7f16\u8bd1\u9636\u6bb5\uff0c\u662f\u4e0d\u9700\u8981\u94fe\u63a5\u52a8\u6001\u5e93\u7684\uff0c\u6240\u4ee5\u5927\u5927\u51cf\u5c11\u4e86\u4ee3\u7801\u6570\u91cf<\/li>\n\n\n\n<li><strong>\u7248\u672c\u63a7\u5236<\/strong>\uff1a\u5982\u679c\u60f3\u4fee\u6539\u5e93\u7684\u5185\u5bb9\uff0c\u53ea\u9700\u8981\u5bf9\u5e93\u8fdb\u884c\u5355\u72ec\u7684\u7f16\u8bd1\uff0c\u800c\u4e0d\u9700\u8981\u5bf9\u6240\u6709\u7a0b\u5e8f\u8fdb\u884c\u91cd\u65b0\u7f16\u8bd1<\/li>\n\n\n\n<li><strong>\u7075\u6d3b\u5ea6\u9ad8<\/strong>\uff1a\u7531\u4e8e\u52a8\u6001\u5e93\u662f\u72ec\u7acb\u4e8e\u7a0b\u5e8f\u4e4b\u5916\u7684\u4ee3\u7801\uff0c\u6240\u4ee5\u5176\u53ef\u64cd\u4f5c\u6027\u5927\u5927\u63d0\u5347\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u6001\u5e93\u7684\u7f3a\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u8fd0\u884c\u65f6\u4f9d\u8d56<\/strong>\uff1a\u7531\u4e8e\u52a8\u6001\u5e93\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u52a0\u8f7d\uff0c\u6240\u4ee5\u5982\u679c\u52a8\u6001\u5e93\u7684\u4f4d\u7f6e\u53d1\u751f\u79fb\u52a8\u3001\u6587\u4ef6\u51fa\u73b0\u635f\u574f\uff0c\u6216\u8005\u5e93\u7684\u7248\u672c\u4e0d\u517c\u5bb9\u90fd\u53ef\u80fd\u5bfc\u81f4\u4f9d\u8d56\u4e8e\u6b64\u52a8\u6001\u5e93\u7684\u7a0b\u5e8f\u51fa\u73b0\u5f02\u5e38\u3002<\/li>\n\n\n\n<li><strong>\u5b89\u5168\u95ee\u9898<\/strong>\uff1a\u7531\u4e8e\u52a8\u6001\u5e93\u5728\u7a0b\u5e8f\u8fd0\u884c\u9636\u6bb5\u88ab\u52a0\u8f7d\uff0c\u6240\u4ee5\u8fd9\u4e2a\u5e93\u662f\u53ef\u4ee5\u88ab\u6076\u610f\u4fee\u6539\u6216\u8005\u66ff\u6362\uff0c\u7531\u6b64\u5f15\u53d1\u6570\u636e\u6cc4\u9732\u3001\u7a0b\u5e8f\u5d29\u6e83\u7b49\u95ee\u9898\u3002<\/li>\n\n\n\n<li><strong>\u5730\u72f1\u4f9d\u8d56\u95ee\u9898<\/strong>\uff1a\u5982\u679c\u4e00\u4e2a\u7a0b\u5e8f\u4f9d\u8d56\u4e24\u4e2a\u52a8\u6001\u5e93\uff0c\u800c\u8fd9\u4e24\u4e2a\u52a8\u6001\u5e93\u4f9d\u8d56\u540c\u4e00\u4e2a\u5e93\uff0c\u4f46\u662f\u8fd9\u4e24\u4e2a\u52a8\u6001\u5e93\u4f9d\u8d56\u7684\u8fd9\u4e00\u4e2a\u5e93\u7684\u7248\u672c\u4e0d\u540c\uff0c\u90a3\u4e48\u4fbf\u53ef\u80fd\u51fa\u73b0\u4e0d\u517c\u5bb9\u95ee\u9898\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u5982\u4f55\u521b\u5efa\u52a8\u6001\u5e93<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">1\u3001\u7f16\u8bd1\u6e90\u4ee3\u7801<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u6001\u5e93\u548c\u9759\u6001\u5e93\u7c7b\u4f3c\uff0c\u4e5f\u662f\u9700\u8981\u5c06\u6e90\u4ee3\u7801\u7f16\u8bd1\u6210<code>.o<\/code>\u76ee\u6807\u6587\u4ef6\uff0c\u4f46\u662f\u548c\u9759\u6001\u5e93\u6709\u533a\u522b\uff0c \u56e0\u4e3a\u9759\u6001\u5e93\u662f\u548c\u7a0b\u5e8f\u4e00\u8d77\u7f16\u8bd1\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\uff0c\u6240\u4ee5\u5728\u5185\u5b58\u4e2d\u7a0b\u5e8f\u662f\u77e5\u9053\u9759\u6001\u5e93\u51fd\u6570\u7684\u4f4d\u7f6e\u7684\uff0c\u5c31\u597d\u6bd4\u4e00\u4e2a\u4eba\uff0c\u9759\u6001\u5e93\u7f16\u8bd1\u4e4b\u540e\u5c31\u662f\u6210\u4e3a\u4e86\u8fd9\u4e2a\u4eba\u7684\u4e00\u90e8\u5206\uff0c\u6bd4\u5982\u624b\uff08\u9759\u6001\u5e93\uff09\uff0c\u4eba\uff08\u7a0b\u5e8f\uff09\u53ef\u4ee5\u6e05\u695a\u5730\u611f\u77e5\u5230\u624b\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u52a8\u6001\u5e93\u4e0d\u540c\uff0c\u52a8\u6001\u5e93\u662f\u5728\u7a0b\u5e8f\u8fd0\u884c\u662f\u52a0\u8f7d\u7684\uff0c\u7a0b\u5e8f\u8c03\u7528\u5b83\u7684\u65f6\u5019\uff0c\u65e0\u6cd5\u77e5\u9053\u5b83\u7684\u4f4d\u7f6e\uff0c\u90a3\u4e48\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u9700\u8981\u5728\u7f16\u8bd1\u7684\u8fc7\u7a0b\u4e2d\u52a0\u4e0a<code>-fPIC<\/code>\u9009\u9879\uff08Position Independent Code\uff0c\u4f4d\u7f6e\u65e0\u5173\u4ee3\u7801\uff09,\u4ece\u800c\u6d88\u9664\u4f4d\u7f6e\u7684\u5f71\u54cd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4\ngcc temp.c -o temp.o -fPIC -c<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">2\u3001\u521b\u5efa\u9759\u6001\u5e93<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528gcc\u7f16\u8bd1\u5668\u548c<code>-shared<\/code>\u9009\u9879\u5c06\u76ee\u6807\u6587\u4ef6\u94fe\u63a5\u4e3a\u4e00\u4e2a\u52a8\u6001\u5e93\u3002\u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>-o<\/code>\u9009\u9879\u6765\u6307\u5b9a\u8f93\u51fa\u6587\u4ef6\u7684\u540d\u79f0\u3002\u52a8\u6001\u5e93\u540c\u6837\u6709\u4e00\u4e2a\u7ea6\u5b9a\u4fd7\u6210\u7684\u547d\u540d\u65b9\u5f0f\u2014\u2014<code>lib\u6587\u4ef6\u540d.so<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4\ngcc temp.o -o libtemp.so -shared <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">3\u3001\u8865\u5145<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u8fd9\u4e2a\u547d\u4ee4\u662f\u548c\u9759\u6001\u5e93\u4e0d\u540c\uff0c\u662f\u53ef\u4ee5\u5b58\u5728\u6bd4\u8f83\u7b80\u7ea6\u7684\u7f16\u8bd1\u547d\u4ee4\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4\ngcc temp.c -o libtemp.so -fPIC -shared<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u5982\u4f55\u8c03\u7528\u52a8\u6001\u5e93<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u6001\u5e93\u7684\u8c03\u7528\u548c\u9759\u6001\u5e93\u6709\u7740\u4e00\u4e9b\u533a\u522b\uff0c\u9996\u5148\u662f\u7a0b\u5e8f\u7f16\u8bd1\u65f6\u94fe\u63a5\u52a8\u6001\u5e93\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u94fe\u63a5\u7a0b\u5e8f\u65f6\u6307\u5b9a\u52a8\u6001\u5e93\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u5728<code>gcc<\/code>\u547d\u4ee4\u884c\u4e2d\u6dfb\u52a0<code>-L<\/code>\u9009\u9879\uff08\u7528\u4e8e\u6307\u5b9a\u5e93\u7684\u641c\u7d22\u8def\u5f84\uff0c\u65e2\u53ef\u4ee5\u662f\u76f8\u5bf9\u8def\u5f84\u4e5f\u53ef\u4ee5\u662f\u7edd\u5bf9\u8def\u5f84\uff09\u548c<code>-l<\/code>\u9009\u9879\uff08\u7528\u4e8e\u6307\u5b9a\u5e93\u7684\u540d\u79f0\uff09\u6765\u5b8c\u6210\u3002\u4f46\u662f\u8fd9\u4e2a\u5e93\u4e0d\u9700\u8981\u5199<code>lib<\/code>\u548c<code>.<\/code>so\u540e\u7f00\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c\u9759\u6001\u5e93\u7c7b\u4f3c\uff0c\u4e5f\u9700\u8981\u5728\u6e90\u4ee3\u7801\u9636\u6bb5\u65f6\u58f0\u660e\u51fd\u6570\uff0c\u52a8\u6001\u5e93\u4e5f\u4f1a\u63d0\u4f9b<code>.h<\/code>\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>include<\/code>\u5305\u542b<code>.h<\/code>\u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4(\u5047\u8bbe\u5f53\u524d\u76ee\u5f55\u5b58\u5728libtemp.so\u52a8\u6001\u5e93)\ngcc main.c -o main -L.\/ -ltemp<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u8fd9\u4ec5\u4ec5\u662f\u8ba9\u6e90\u4ee3\u7801\u7f16\u8bd1\u7684\u65f6\u5019\u77e5\u9053\u6709\u8fd9\u4e2a\u52a8\u6001\u5e93\u7684\u5b58\u5728\uff0c\u5728\u5b9e\u9645\u8fd0\u884c\u7a0b\u5e8f\u7684\u65f6\u5019\uff0c\u8fd8\u5e94\u8be5\u901a\u8fc7\u5176\u4ed6\u989d\u5916\u7684\u64cd\u4f5c\u6765\u6307\u5b9a\u52a8\u6001\u5e93\u7684\u4f4d\u7f6e\uff0c\u4ee5\u544a\u8bc9\u64cd\u4f5c\u7cfb\u7edf\u5728\u4ec0\u4e48\u5730\u65b9\u80fd\u627e\u5230\u8be5\u52a8\u6001\u5e93<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u63d0\u4f9b\u51e0\u79cd\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">1\u3001\u4f7f\u7528rpath\u6216RUNPATH<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>rpath<\/code>\u6216<code>RUNPATH<\/code>\u662f\u94fe\u63a5\u5668\u7684\u4e00\u4e2a\u9009\u9879\uff0c\u5b83\u5141\u8bb8\u5728\u7f16\u8bd1\u7a0b\u5e8f\u65f6\u6307\u5b9a\u52a8\u6001\u5e93\u7684\u641c\u7d22\u8def\u5f84\u3002\u8fd9\u4e2a\u8def\u5f84\u4f1a\u88ab\u5d4c\u5165\u5230\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528<code>-Wl,-rpath,\u8def\u5f84<\/code>\u9009\u9879\u6765\u8bbe\u7f6e<code>rpath<\/code>\u3002<code>-Wl<\/code>\u544a\u8bc9<code>gcc<\/code>\u5c06\u540e\u9762\u7684\u9009\u9879\u4f20\u9012\u7ed9\u94fe\u63a5\u5668\uff0c<code>-rpath<\/code>\u662f\u94fe\u63a5\u5668\u7684\u4e00\u4e2a\u9009\u9879\uff0c\u540e\u9762\u8ddf\u7740\u7684\u662f\u4f60\u8981\u8bbe\u7f6e\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u4f18\u70b9<\/mark>\uff1a<code>rpath<\/code>\u6216<code>RUNPATH<\/code>\u4f1a\u88ab\u5d4c\u5165\u5230\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\uff0c\u56e0\u6b64\u65e0\u8bba\u4f60\u5728\u4f55\u5904\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5b83\u90fd\u80fd\u627e\u5230\u6b63\u786e\u7684\u52a8\u6001\u5e93\uff0c\u8fd9\u4f7f\u5f97\u7a0b\u5e8f\u7684\u79fb\u690d\u6027\u66f4\u5f3a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u7f3a\u70b9<\/mark>\uff1a\u5982\u679c\u52a8\u6001\u5e93\u7684\u4f4d\u7f6e\u6539\u53d8\u4e86\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u91cd\u65b0\u7f16\u8bd1\u4f60\u7684\u7a0b\u5e8f\uff0c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u793a\u4f8b<\/mark>\uff1a\uff08\u5047\u8bbe\u5728\u5f53\u524d\u76ee\u5f55\u5b58\u5728\u4e00\u4e2a\u52a8\u6001\u5e93libtemp.so\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc main.c -o main -L. -ltemp -Wl,-rpath,.<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u8865\u5145<\/mark>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u65b9\u5f0f\u662f\u5c06\u7cfb\u7edf\u6307\u5b9a\u4e86\u4e00\u4e2a\u65b0\u7684\u5bfb\u627e\u5e93\u7684\u8def\u5f84\uff0c\u5b9e\u9645\u4e0a\u5982\u679c\u5728\u8def\u5f84\u4e2d\u627e\u4e0d\u5230\u9700\u8981\u7684\u5e93\uff0c\u7cfb\u7edf\u4fbf\u4f1a\u56de\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u5bfb\u627e\uff0c\u6240\u4ee5\u5c31\u53ef\u80fd\u4ea7\u751f<mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">\u4e0d\u540c\u8def\u5f84\u540c\u540d\u5e93<\/mark>\u7684\u60c5\u51b5\uff0c\u5982\u679c\u540c\u540d\u5e93\u529f\u80fd\u4e0d\u540c\u6216\u8005\u7248\u672c\u4e0d\u540c\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7a0b\u5e8f\u5f02\u5e38\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">2\u3001\u4f7f\u7528<code>LD_LIBRARY_PATH<\/code>\u73af\u5883\u53d8\u91cf<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>LD_LIBRARY_PATH<\/code>\u662f\u4e00\u4e2a\u73af\u5883\u53d8\u91cf\uff0c\u7528\u4e8e\u5728Linux\u548c\u5176\u4ed6\u7c7bUnix\u7cfb\u7edf\u4e2d\u6307\u5b9a\u52a8\u6001\u94fe\u63a5\u5668\u641c\u7d22\u52a8\u6001\u5e93\u7684\u8def\u5f84\u3002\u5f53\u4f60\u8fd0\u884c\u4e00\u4e2a\u7a0b\u5e8f\u65f6\uff0c\u52a8\u6001\u94fe\u63a5\u5668\u9700\u8981\u627e\u5230\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u52a8\u6001\u5e93\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0d\u8fc7\u8fd9\u79cd\u65b9\u5f0f\u662f\u4e00\u4e2a\u4e34\u65f6\u6027\u7684\u64cd\u4f5c\uff0c\u53ea\u6709\u5728\u5f53\u524d\u7684shell\u4e2d\u6709\u7528\uff0c\u6240\u4ee5\u5f80\u5f80\u88ab\u7528\u4e8e\u5bf9\u5e93\u7684\u6d4b\u8bd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u4f18\u70b9<\/mark>\uff1a<code>LD_LIBRARY_PATH<\/code>\u53ef\u4ee5\u4e34\u65f6\u6539\u53d8\u52a8\u6001\u5e93\u7684\u641c\u7d22\u8def\u5f84\uff0c\u8fd9\u5728\u6d4b\u8bd5\u65b0\u5e93\u6216\u8005\u975e\u6807\u51c6\u5b89\u88c5\u7684\u5e93\u65f6\u975e\u5e38\u6709\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u7f3a\u70b9<\/mark>\uff1a<code>LD_LIBRARY_PATH<\/code>\u53ea\u5bf9\u5f53\u524d\u7684shell\u4f1a\u8bdd\u6709\u6548\uff0c\u5982\u679c\u5f00\u542f\u4e86\u4e00\u4e2a\u65b0\u7684shell\u4f1a\u8bdd\uff0c\u9700\u8981\u91cd\u65b0\u8bbe\u7f6e<code>LD_LIBRARY_PATH<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u793a\u4f8b<\/mark>\uff1a\uff08\u5047\u8bbe\u5728\u5f53\u524d\u76ee\u5f55\u5b58\u5728\u4e00\u4e2a\u52a8\u6001\u5e93libtemp.so\uff09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export LD_LIBRARY_PATH=\/home\/user\/mylibs<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u8865\u5145<\/mark>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2d\u65b9\u5f0f\u662f\u4e34\u65f6\u6027\u7684\u5c06\u7cfb\u7edf\u6307\u5b9a\u4e86\u4e00\u4e2a\u65b0\u7684\u5bfb\u627e\u5e93\u7684\u8def\u5f84\uff0c\u5b9e\u9645\u4e0a\u5982\u679c\u5728\u8def\u5f84\u4e2d\u627e\u4e0d\u5230\u9700\u8981\u7684\u5e93\uff0c\u7cfb\u7edf\u4fbf\u4f1a\u56de\u5230\u7cfb\u7edf\u8def\u5f84\u4e2d\u5bfb\u627e\uff0c\u6240\u4ee5\u5c31\u53ef\u80fd\u4ea7\u751f<mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">\u4e0d\u540c\u8def\u5f84\u540c\u540d\u5e93<\/mark>\u7684\u60c5\u51b5\uff0c\u5982\u679c\u540c\u540d\u5e93\u529f\u80fd\u4e0d\u540c\u6216\u8005\u7248\u672c\u4e0d\u540c\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u7a0b\u5e8f\u5f02\u5e38\u3002\u800c\u4e14\u5bf9\u4e8e\u4e0d\u540c\u7684\u8bbe\u5907\uff0c\u751a\u81f3\u540c\u4e00\u8bbe\u5907\u7684\u4e0d\u540cshell\u90fd\u4f1a\u51fa\u73b0\u5dee\u5f02\uff0c\u6240\u4ee5\u51e0\u4e4e\u6ca1\u6709\u79fb\u690d\u6027\u53ef\u8a00\uff0c\u800c\u5b9e\u9645\u5f00\u53d1\u4e2d\u8fd9\u79cd\u65b9\u5f0f\u6bd4\u8f83\u9002\u5408\u6d4b\u8bd5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">3\u3001\u4f7f\u7528<code>\/etc\/ld.so.conf<\/code>\u6587\u4ef6<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>\/etc\/ld.so.conf<\/code>\u662f\u4e00\u4e2a\u7cfb\u7edf\u7ea7\u522b\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u7528\u4e8e\u6307\u5b9a\u52a8\u6001\u94fe\u63a5\u5668\u641c\u7d22\u52a8\u6001\u5e93\u7684\u8def\u5f84\u3002\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u53ef\u4ee5\u5305\u542b\u4e00\u7cfb\u5217\u7684\u76ee\u5f55\u8def\u5f84\uff0c\u6bcf\u4e2a\u8def\u5f84\u5360\u4e00\u884c\u3002\u5f53\u4f60\u8fd0\u884c\u4e00\u4e2a\u7a0b\u5e8f\u65f6\uff0c\u52a8\u6001\u94fe\u63a5\u5668\u4f1a\u5728\u8fd9\u4e9b\u76ee\u5f55\u4e2d\u67e5\u627e\u9700\u8981\u7684\u52a8\u6001\u5e93\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u4f18\u70b9<\/mark>\uff1a\u8fd9\u662f\u4e00\u4e2a\u5168\u5c40\u7684\u8bbe\u7f6e\uff0c\u5bf9\u6240\u6709\u7528\u6237\u548c\u7a0b\u5e8f\u90fd\u6709\u6548\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u7f3a\u70b9<\/mark>\uff1a\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u3002\u6b64\u5916\uff0c\u6bcf\u6b21\u4fee\u6539<code>\/etc\/ld.so.conf<\/code>\u540e\uff0c\u90fd\u9700\u8981\u8fd0\u884c<code>ldconfig<\/code>\u6765\u66f4\u65b0\u914d\u7f6e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u793a\u4f8b1<\/mark>\uff1a\u5047\u8bbe\u52a8\u6001\u5e93\u4f4d\u4e8e<code>\/home\/user\/mylibs<\/code>\u76ee\u5f55\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"\/home\/user\/mylibs\" | sudo tee -a \/etc\/ld.so.conf\nsudo ldconfig<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5c06<code>\/home\/user\/mylibs<\/code>\u6dfb\u52a0\u5230<code>\/etc\/ld.so.conf<\/code>\u6587\u4ef6\u7684\u672b\u5c3e\u3002<code>tee -a<\/code>\u547d\u4ee4\u7528\u4e8e\u5c06\u8f93\u5165\u8ffd\u52a0\u5230\u6587\u4ef6\u4e2d\uff0c<code>sudo<\/code>\u547d\u4ee4\u7528\u4e8e\u83b7\u53d6\u7ba1\u7406\u5458\u6743\u9650\uff0c\u56e0\u4e3a\u4fee\u6539<code>\/etc\/ld.so.conf<\/code>\u6587\u4ef6\u901a\u5e38\u9700\u8981\u7ba1\u7406\u5458\u6743\u9650\u3002\u4e0d\u8fc7\u8981\u6ce8\u610f\u7684\u662f\u52a8\u6001\u5e93\u7684\u8def\u5f84<mark style=\"background-color:#7bdcb5\" class=\"has-inline-color\">\u5fc5\u987b\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u8865\u5145<\/mark>\uff1a\u4e00\u4e9bLinux\u53d1\u884c\u7248\uff08\u5982Debian\uff0cUbuntu\u7b49\uff09\u63d0\u4f9b\u4e86<code><mark style=\"background-color:#ff6900\" class=\"has-inline-color\">\/etc\/ld.so.conf.d\/<\/mark><\/code>\u76ee\u5f55\uff0c\u4f60\u53ef\u4ee5\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u521b\u5efa\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4fee\u6539<code>\/etc\/ld.so.conf<\/code>\u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u8ba9\u4f60\u66f4\u65b9\u4fbf\u5730\u7ba1\u7406\u4f60\u7684\u5e93\u8def\u5f84\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#8ed1fc\" class=\"has-inline-color\">\u793a\u4f8b2<\/mark>\uff1a\u5047\u8bbe\u52a8\u6001\u5e93\u4f4d\u4e8e<code>\/home\/user\/mylibs<\/code>\u76ee\u5f55\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo \"\/home\/user\/mylibs\" | sudo tee \/etc\/ld.so.conf.d\/mylibs.conf\nsudo ldconfig<mark style=\"background-color:#fcb900\" class=\"has-inline-color\"><\/mark><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">4\u3001\u5c06\u52a8\u6001\u5e93\u653e\u5165\u7cfb\u7edf\u8def\u5f84\uff08\u4f8b\u5982\/usr\/lib\uff09<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u70b9\uff1a\u7b80\u5355\u3001\u4e0d\u9700\u8981\u989d\u5916\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f3a\u70b9\uff1a\u53ef\u79fb\u690d\u6027\u5dee<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7684\u9ad8\u7ea7\u4e3b\u9898<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a8\u6001\u64cd\u4f5c\u5e93<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">dl\u5e93\u7684\u6982\u5ff5<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4ee5\u4e0b\u573a\u666f\uff1a\u5728\u5f00\u53d1\u4e00\u4e2a\u7a0b\u5e8f\u540e\uff0c\u53ef\u80fd\u5728\u540e\u671f\u6709\u52a8\u6001\u5e93\u5bf9\u8fd9\u4e2a\u7a0b\u5e8f\u529f\u80fd\u8fdb\u884c\u4fee\u6539\u3002\u7531\u4e8e\u8fd9\u4e2a\u52a8\u6001\u5e93\u5728\u76ee\u524d\u5904\u4e8e\u672a\u5f00\u53d1\u9636\u6bb5\uff0c\u6240\u4ee5\u5934\u6587\u4ef6\u751a\u81f3\u662f\u5e93\u540d\u79f0\u90fd\u5904\u4e8e\u672a\u77e5\u72b6\u6001\u3002\u90a3\u4e48\u5982\u4f55\u5728\u4e0d\u91cd\u65b0\u4fee\u6539\u6e90\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u8ba9\u52a8\u6001\u5e93\u52a0\u8f7d\u5230\u7a0b\u5e8f\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u79cd\u52a8\u6001\u64cd\u4f5c\u7684\u529f\u80fd\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u7528\u5230\u5e93\u2014\u2014<code>libdl.so<\/code>\uff0c\u5934\u6587\u4ef6<code>dlfcn.h<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">libdl.so\u5e93\u662f\u4e00\u64cd\u4f5c\u7cfb\u7edf\u7ea7\u522b\u7684\u5e93\uff0c\u9075\u5faaPOSIX\u6807\u51c6\uff08Portable Operating System Interface\uff09\uff0c\u4e3b\u8981\u7528\u4e8e\u652f\u6301\u7a0b\u5e8f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5730\u52a0\u8f7d\u548c\u5378\u8f7d\u5171\u4eab\u5bf9\u8c61\u6587\u4ef6\uff08\u4e5f\u5c31\u662f\u52a8\u6001\u94fe\u63a5\u5e93\uff09\uff0c\u5e76\u83b7\u53d6\u5176\u4e2d\u5b9a\u4e49\u7684\u7b26\u53f7\uff08symbol\uff09\u5e76\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u5e93\u5b58\u5728\u52a8\u6001\u5e93\u7248\u672c\u548c\u9759\u6001\u5e93\u7248\u672c\uff0c\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u4f7f\u7528\u52a8\u6001\u7248\u672c\u4e5f\u5c31\u662f.so<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4\ngcc main.c -o main -ldl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u5e0c\u671b\u4f7f\u7528\u9759\u6001\u5e93\u53ef\u4ee5\u7279\u6307\u9759\u6001\u5e93<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u793a\u4f8b\u547d\u4ee4\ngcc main.c -o main -ldl -static<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u5e93\u4e2d\u63d0\u4f9b\u4e86\u4e00\u7ec4\u51fd\u6570\uff0c\u4e3b\u8981\u4e3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>dlopen<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u6253\u5f00\u4e00\u4e2a\u52a8\u6001\u94fe\u63a5\u5e93\u6587\u4ef6\u5e76\u8fd4\u56de\u4e00\u4e2a\u53e5\u67c4\uff0c\u8be5\u53e5\u67c4\u7528\u4e8e\u540e\u7eed\u7684\u64cd\u4f5c\uff0c\u5982\u67e5\u627e\u7b26\u53f7\u3001\u5173\u95ed\u5e93\u7b49<\/li>\n\n\n\n<li><code>dlsym<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u5728\u6253\u5f00\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u4e2d\u67e5\u627e\u6307\u5b9a\u7684\u7b26\u53f7\uff0c\u5e76\u8fd4\u56de\u7b26\u53f7\u7684\u5730\u5740<\/li>\n\n\n\n<li><code>dlclose<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u5173\u95ed\u5148\u524d\u6253\u5f00\u7684\u52a8\u6001\u94fe\u63a5\u5e93<\/li>\n\n\n\n<li><code>dlerror<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u8fd4\u56de\u6700\u8fd1\u4e00\u6b21\u52a8\u6001\u94fe\u63a5\u5e93\u64cd\u4f5c\u7684\u9519\u8bef\u4fe1\u606f<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\u52a0\u8f7d\u52a8\u6001\u5e93<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dlopen\u51fd\u6570<\/code>\u662f\u5728<code>Unix-like<\/code>\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u52a8\u6001\u5e93\u52a0\u8f7d\u51fd\u6570\uff0c\u5b83\u7684\u4f5c\u7528\u662f\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5730\u52a0\u8f7d\u5171\u4eab\u5e93\u6587\u4ef6\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u8be5\u5e93\u7684\u53e5\u67c4\uff0c\u4ee5\u4f9b\u540e\u7eed\u4f7f\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u539f\u578b\uff1a<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void *dlopen(const char *filename, int flag);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u53c2\u6570\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>filename<\/code>\uff1a\u8fd9\u662f\u4f60\u60f3\u8981\u6253\u5f00\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u6587\u4ef6\u540d\u3002\u5982\u679c<code>filename<\/code>\u662f<code>NULL<\/code>\uff0c\u90a3\u4e48\u8fd4\u56de\u7684\u53e5\u67c4\u662f\u4e3b\u7a0b\u5e8f\u7684\u53e5\u67c4<\/li>\n\n\n\n<li><code>flag<\/code>\uff1a\u8fd9\u662f\u6253\u5f00\u5e93\u7684\u65b9\u5f0f\uff0c\u4e3b\u8981\u6709\u4e24\u79cd\uff1a\n<ul class=\"wp-block-list\">\n<li><code>RTLD_LAZY<\/code>\uff1a\u8fdb\u884c\u61d2\u60f0\u7ed1\u5b9a\uff0c\u53ea\u6709\u5728\u5f15\u7528\u5230\u5e93\u4e2d\u7684\u51fd\u6570\u65f6\u624d\u4f1a\u89e3\u6790\u7b26\u53f7\u3002<\/li>\n\n\n\n<li><code>RTLD_NOW<\/code>\uff1a\u7acb\u5373\u89e3\u6790\u5e93\u4e2d\u6240\u6709\u672a\u5b9a\u4e49\u7684\u7b26\u53f7\u3002\u5982\u679c\u65e0\u6cd5\u89e3\u6790\u6240\u6709\u7684\u7b26\u53f7\uff0c<code>dlopen<\/code>\u4f1a\u8fd4\u56de<code>NULL<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">RTLD\uff08run-time dynamic loading\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u8fd4\u56de\u503c\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd4\u56de\u52a8\u6001\u5e93\u7684\u53e5\u67c4<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u4f7f\u7528\u793a\u4f8b\uff1a<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;dlfcn.h&gt;\n\/\/...\nvoid* handle = dlopen(\".\/home\/user\/mylib\/libtemp.so\",RTLD_LAZY);\/\/\u61d2\u52a0\u8f7d\n\/\/...<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u67e5\u627e\u51fd\u6570<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dlsym\u51fd\u6570<\/code>\u7528\u4e8e\u5728\u8fd0\u884c\u65f6\u67e5\u627e\u52a8\u6001\u94fe\u63a5\u5e93\u4e2d\u7684\u7b26\u53f7\u3002\u8fd9\u5bf9\u4e8e\u5b9e\u73b0\u63d2\u4ef6\u67b6\u6784\u6216\u9700\u8981\u5728\u8fd0\u884c\u65f6\u52a0\u8f7d\u4ee3\u7801\u7684\u5e94\u7528\u7a0b\u5e8f\u975e\u5e38\u6709\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u539f\u578b\uff1a<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void *dlsym(void *handle, const char *symbol);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u53c2\u6570\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>handle<\/code>\uff1a\u8fd9\u662f\u4e00\u4e2a\u7531dlopen\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\uff0c\u5b83\u6307\u5411\u4f60\u60f3\u8981\u67e5\u8be2\u7684\u52a8\u6001\u94fe\u63a5\u5e93\u3002<\/li>\n\n\n\n<li><code>symbol<\/code>\uff1a\u8fd9\u662f\u4f60\u60f3\u8981\u67e5\u627e\u7684\u7b26\u53f7\u7684\u540d\u79f0\uff0c\u53ef\u4ee5\u662f\u53d8\u91cf\u540d\u6216\u51fd\u6570\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u8fd4\u56de\u503c\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u627e\u5230\u4e86\u7b26\u53f7\uff0cdlsym\u51fd\u6570\u4f1a\u8fd4\u56de\u4e00\u4e2a\u6307\u5411\u8be5\u7b26\u53f7\u7684\u6307\u9488\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u6ca1\u6709\u627e\u5230\u7b26\u53f7\uff0cdlsym\u51fd\u6570\u4f1a\u8fd4\u56deNULL\uff0c\u5e76\u8bbe\u7f6e\u76f8\u5e94\u7684\u9519\u8bef\u6d88\u606f\uff0c\u53ef\u4ee5\u901a\u8fc7dlerror\u51fd\u6570\u83b7\u53d6\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u793a\u4f8b\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe<code>.\/home\/user\/mylib\/libtemp.so<\/code>\u5e93\u4e2d\u6709\u4e00\u4e2a\u51fd\u6570<code>int add(int a,int b)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;dlfcn.h&gt;\n\/\/...\nvoid* handle = dlopen(\".\/home\/user\/mylib\/libtemp.so\",RTLD_LAZY);\nint (*lib_add)(int,int) = (int (*)(int,int))dlsym(handle,\"add\");\n\/\/...<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u9519\u8bef\u5904\u7406\u3002<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><code>dlerror<\/code>\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u6700\u8fd1\u4e00\u6b21\u52a8\u6001\u94fe\u63a5\u64cd\u4f5c\u7684\u9519\u8bef\u6d88\u606f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u539f\u578b\uff1a<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char *dlerror(void);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u8fd4\u56de\u503c\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>dlerror<\/code>\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a\u63cf\u8ff0\u6700\u8fd1\u4e00\u6b21\u4ece<code>dlopen<\/code>\uff0c<code>dlsym<\/code>\u6216<code>dlclose<\/code>\u53d1\u751f\u7684\u9519\u8bef\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u81ea\u521d\u59cb\u5316\u4ee5\u6765\u6216\u81ea\u4e0a\u6b21\u8c03\u7528\u4ee5\u6765\u6ca1\u6709\u53d1\u751f\u9519\u8bef\uff0c<code>dlerror<\/code>\u51fd\u6570\u5c06\u8fd4\u56de<code>NULL<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u793a\u4f8b\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe<code>.\/home\/user\/mylib\/libtemp.so<\/code>\u5e93\u4e2d\u6709\u4e00\u4e2a\u51fd\u6570<code>int add(int a,int b)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;dlfcn.h&gt;\n\/\/...\nvoid* handle = dlopen(\".\/home\/user\/mylib\/libtemp.so\",RTLD_LAZY);\nint (*lib_add)(int,int) = (int (*)(int,int))dlsym(handle,\"add\");\nchar *error = dlerror();\n\/\/...<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u5378\u8f7d\u52a8\u6001\u5e93<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u539f\u578b\uff1a<\/mark><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int dlclose(void *handle);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u53c2\u6570\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>handle<\/code>\uff1a\u8fd9\u662f\u4e00\u4e2a\u7531dlopen\u51fd\u6570\u8fd4\u56de\u7684\u53e5\u67c4\uff0c\u5b83\u6307\u5411\u4f60\u60f3\u8981\u5173\u95ed\u7684\u52a8\u6001\u94fe\u63a5\u5e93<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u8fd4\u56de\u503c\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u6210\u529f\u5173\u95ed\u4e86\u5f15\u7528\u7684\u7b26\u53f7\u8868\u53e5\u67c4\uff0c<code>dlclose<\/code>\u51fd\u6570\u5c06\u8fd4\u56de0\u3002<\/li>\n\n\n\n<li>\u5982\u679c<code>handle<\/code>\u4e0d\u6307\u5411\u4e00\u4e2a\u6253\u5f00\u7684\u7b26\u53f7\u8868\u53e5\u67c4\uff0c\u6216\u8005\u5982\u679c\u65e0\u6cd5\u5173\u95ed\u7b26\u53f7\u8868\u53e5\u67c4\uff0cdlclose\u51fd\u6570\u5c06\u8fd4\u56de\u4e00\u4e2a\u975e\u96f6\u503c\u3002<\/li>\n\n\n\n<li>\u66f4\u8be6\u7ec6\u7684\u8bca\u65ad\u4fe1\u606f\u53ef\u4ee5\u901a\u8fc7<code>dlerror<\/code>\u51fd\u6570\u83b7\u5f97\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u4f5c\u7528\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>dlclose<\/code>\u51fd\u6570\u7528\u4e8e\u901a\u77e5\u7cfb\u7edf\uff0c\u5e94\u7528\u7a0b\u5e8f\u4e0d\u518d\u9700\u8981\u7531<code>handle<\/code>\u6307\u5b9a\u7684\u7b26\u53f7\u8868\u53e5\u67c4\u3002<\/li>\n\n\n\n<li>\u5f53\u7b26\u53f7\u8868\u53e5\u67c4\u88ab\u5173\u95ed\u65f6\uff0c\u5b9e\u73b0\u53ef\u80fd\u4f1a\u5378\u8f7d\u7531<code>dlopen<\/code>\u5728\u6253\u5f00\u7b26\u53f7\u8868\u53e5\u67c4\u65f6\u52a0\u8f7d\u7684\u53ef\u6267\u884c\u5bf9\u8c61\u6587\u4ef6\uff0c\u4ee5\u53ca\u7531<code>dlsym<\/code>\u5728\u4f7f\u7528\u7531<code>handle<\/code>\u6807\u8bc6\u7684\u7b26\u53f7\u8868\u53e5\u67c4\u65f6\u52a0\u8f7d\u7684\u90a3\u4e9b\u3002<\/li>\n\n\n\n<li>\u4e00\u65e6\u7b26\u53f7\u8868\u53e5\u67c4\u5df2\u7ecf\u88ab\u5173\u95ed\uff0c\u5e94\u7528\u7a0b\u5e8f\u5e94\u8be5\u5047\u8bbe\u4efb\u4f55\u4f7f\u7528<code>handle<\/code>\u4f7f\u4e4b\u53ef\u89c1\u7684\u7b26\u53f7\uff08\u51fd\u6570\u6807\u8bc6\u7b26\u548c\u6570\u636e\u5bf9\u8c61\u6807\u8bc6\u7b26\uff09\u5bf9\u8fdb\u7a0b\u6765\u8bf4\u90fd\u4e0d\u518d\u53ef\u7528<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u51fd\u6570\u793a\u4f8b\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe<code>.\/home\/user\/mylib\/libtemp.so<\/code>\u5e93\u4e2d\u6709\u4e00\u4e2a\u51fd\u6570<code>int add(int a,int)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include&lt;dlfcn.h&gt;\n\/\/...\nvoid* handle = dlopen(\".\/home\/user\/mylib\/libtemp.so\",RTLD_LAZY);\n\/\/...\ndlclose(handle);\n\/\/...<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u7efc\u5408<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe\u5b58\u5728<code>main.c<\/code>\u6587\u4ef6\uff0c\u4e14\u540c\u76ee\u5f55\u4e0b\u5b58\u5728<code>mylib<\/code>\u76ee\u5f55\uff0c\u8be5\u76ee\u5f55\u4e2d\u5b58\u5728\u4e00\u4e2a\u52a8\u6001\u5e93<code>libtemp.so<\/code>\uff0c\u8be5\u5e93\u4e2d\u6709\u4e00\u4e2a\u51fd\u6570<code>int add(int a,int b)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/main.c\n#include&lt;stdio.h&gt;\n#include&lt;dlfcn.h&gt; \/\/dl\u5e93\n#include&lt;stdlib.h&gt;\n\nint main(){\n    void *handle = dlopen(\".\/mylib\/libtemp.so\",RTLD_LAZY);\/\/\u4ee5\u61d2\u52a0\u8f7d\u7684\u65b9\u5f0f\u52a0\u8f7dlibtemp.so\u52a8\u6001\u5e93\uff0c\u83b7\u53d6\u8be5\u5e93\u7684\u53e5\u67c4\n    if(!handle){\/\/\u5224\u65ad\u662f\u5426\u83b7\u53d6\u6210\u529f\n        fprintf(stderr,\"%s\\n\",dlerror());\/\/\u5c06\u9519\u8bef\u4fe1\u606f\u8f93\u5165\u5230\u6807\u51c6\u9519\u8bef\u6d41\u4e2d\n        exit(EXIT_FAILURE);\n    }\n\n    dlerror();\/\/\u83b7\u53d6\u5e76\u6e05\u7406\u4e4b\u524d\u7684\u9519\u8bef\u4fe1\u606f\u3002\n\n    int (*add)(int,int) = (int (*)(int ,int ))dlsym(handle,\"add\");\/\/\u8fdb\u884c\u52a8\u6001\u5e93\u7684\u51fd\u6570\u7b26\u53f7\u89e3\u6790\n    if(!add){\/\/\u5224\u65ad\u662f\u5426\u89e3\u6790\u5931\u8d25\n        fprintf(stderr,\"%s\\n\",dlerror());\/\/\u5c06\u9519\u8bef\u4fe1\u606f\u8f93\u5165\u5230\u6807\u51c6\u9519\u8bef\u6d41\u4e2d\n        exit(EXIT_FAILURE);\n    }\n\n    int a = 1, b = 2;\n    printf(\"a + b = %d\\n\",add(a,b));\/\/\u8c03\u7528\u51fd\u6570add\n\n    if(dlclose(handle)){\/\/\u5224\u65ad\u662f\u5426\u52a8\u6001\u5e93\u5173\u95ed\u5931\u8d25\n        fprintf(stderr,\"%s\\n\",dlerror());\/\/\u5c06\u9519\u8bef\u4fe1\u606f\u8f93\u5165\u5230\u6807\u51c6\u9519\u8bef\u6d41\u4e2d\n        exit(EXIT_FAILURE);\n    }\n    exit(EXIT_SUCCESS);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gcc main.c -o main -ldl<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a + b = 3<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">\u8865\u5145\uff1a<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u8bbf\u95eedlfcn.h\u6587\u4ef6\uff0c\u53d1\u73b0\u5176\u4e2d\u8fd8\u6709\u5176\u4ed6\u7684\u51fd\u6570\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>dlmopen<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7c7b\u4f3c\u4e8e<code>dlopen<\/code>\uff0c\u4f46\u662f\u5b83\u4f1a\u8bf7\u6c42\u5728\u4e00\u4e2a\u65b0\u7684\u547d\u540d\u7a7a\u95f4\u4e2d\u5206\u914d\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li><code>dlvsym<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7c7b\u4f3c\u4e8e<code>dlsym<\/code>\uff0c\u4f46\u662f\u5b83\u4f1a\u67e5\u627e\u5177\u6709\u6307\u5b9a\u7248\u672c\u7684\u7b26\u53f7\u3002<\/li>\n\n\n\n<li><code>dladdr<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u5730\u5740\uff0c\u7136\u540e\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u8be5\u5730\u5740\u7684\u5bf9\u8c61\u7684\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><code>dladdr1<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7c7b\u4f3c\u4e8e<code>dladdr<\/code>\uff0c\u4f46\u662f\u5b83\u4f1a\u6839\u636e\u6307\u5b9a\u7684\u6807\u5fd7\u8bbe\u7f6e\u989d\u5916\u7684\u4fe1\u606f\u3002<\/li>\n\n\n\n<li><code>dlinfo<\/code>\uff1a\u8fd9\u4e2a\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u52a8\u6001\u94fe\u63a5\u5e93\u7684\u4fe1\u606f\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u51fd\u6570\u548c\u53c2\u6570\u5747\u6709\u5176\u4ed6\u62d3\u5c55\uff0c\u8be6\u60c5\u8bf7\u81ea\u884c\u8bbf\u95ee<code>dlfcn.h<\/code>\u6587\u4ef6<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7248\u672c\u63a7\u5236<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u52a8\u6001\u5e93\u7684\u7248\u672c\u63a7\u5236\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u95ee\u9898\u3002\u52a8\u6001\u5e93\u7684\u7248\u672c\u63a7\u5236\u4e3b\u8981\u901a\u8fc7\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762\u6765\u5b9e\u73b0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">1\u3001\u7248\u672c\u53f7\uff1a<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Linux\u901a\u8fc7\u7248\u672c\u53f7\u6765\u7ba1\u7406\u52a8\u6001\u5e93\u7684\u7248\u672c\uff0c\u7248\u672c\u53f7\u6700\u591a\u67093\u7ea7\uff0c\u5176\u683c\u5f0f\u4e3alibname.so.x.y.z\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>x\u8868\u793a\u4e3b\u7248\u672c\u53f7\uff0c\u975e\u517c\u5bb9\u4fee\u6539\uff0c\u53ef\u80fd\u5bf9\u63a5\u53e3\u505a\u4e86\u5927\u6539\u52a8\uff0c\u6bd4\u5982\u91cd\u547d\u540d\u3001\u589e\u52a0\u6216\u51cf\u5c11\u53c2\u6570\u7b49<\/li>\n\n\n\n<li>y\u8868\u793a\u6b21\u7248\u672c\u53f7\uff0c\u4e0d\u6539\u53d8\u517c\u5bb9\u6027\uff0c\u4f46\u662f\u589e\u52a0\u4e86\u65b0\u63a5\u53e3<\/li>\n\n\n\n<li>z\u8868\u793a\u4fee\u8ba2\u7248\u672c\u53f7\uff0c\u4e0d\u6539\u53d8\u517c\u5bb9\u6027\uff0c\u4ec5\u4ec5\u662f\u4fee\u590dbug\u3001\u6216\u8005\u4f18\u5316\u4ee3\u7801\u5b9e\u73b0\u3001\u4f18\u5316\u6027\u80fd\u7b49<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">2\u3001\u8f6f\u94fe\u63a5<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f6f\u94fe\u63a5\u662f\u6587\u4ef6\u7cfb\u7edf\u7684\u4e2d\u4e00\u79cd\u5143\u7d20\uff0c\u5b58\u50a8\u4e86\u5305\u542b\u53e6\u4e00\u4e2a\u6587\u4ef6\u8def\u5f84\u7684\u5b57\u7b26\u4e32\u3002\u5f53\u63d0\u4f9b\u4e86\u65b0\u7248\u672c\u7684\u52a8\u6001\u5e93\u65f6\uff0c\u53ea\u9700\u5c06\u65b0\u7248\u672c\u7684\u52a8\u6001\u5e93\u6587\u4ef6\u590d\u5236\u5230\u4e4b\u524d\u7248\u672c\u7684\u76ee\u5f55\u4e0b\uff0c\u7136\u540e\u5c06\u8f6f\u94fe\u63a5\u6307\u5411\u4fee\u6539\u5230\u65b0\u7248\u672c\u7684\u6587\u4ef6\u5373\u53ef<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">3\u3001SONAME<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SONAME\u662f\u7f16\u8bd1\u751f\u6210\u52a8\u6001\u94fe\u63a5\u5e93\u65f6\u901a\u8fc7-soname\u9009\u9879\u6307\u5b9a\u7684\u4e00\u4e2a\u5b57\u6bb5\uff0c\u4f1a\u88ab\u5199\u5165so\u7684\u6587\u4ef6\u5f53\u4e2d\uff0c\u7528\u4e8e\u7ba1\u7406\u7248\u672c\u3002\u901a\u8fc7\u5f62\u5982gcc -Wl,-soname,libhello.so.1 \u7684\u65b9\u5f0f\u6307\u5b9a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">4\u3001ldconfig<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">ldconfig\u662f\u4e00\u4e2a\u52a8\u6001\u94fe\u63a5\u5e93\u7ba1\u7406\u547d\u4ee4\uff0c\u5176\u76ee\u7684\u4e3a\u4e86\u8ba9\u52a8\u6001\u94fe\u63a5\u5e93\u4e3a\u7cfb\u7edf\u6240\u5171\u4eab\u3002ldconfig\u9ed8\u8ba4\u641c\u5bfb\/lib\u548c\/usr\/lib\uff0c\u4ee5\u53ca\u914d\u7f6e\u6587\u4ef6\/etc\/ld.so.conf\u5185\u6240\u5217\u7684\u76ee\u5f55\u4e0b\u7684\u5e93\u6587\u4ef6\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u8865\u5145<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">\u5e93\u7684\u62d3\u5c55<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u7cfb\u7edf\u5e93\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>glibc\uff1aGNU C\u5e93\uff0c\u662f\u5927\u591a\u6570Linux\u7cfb\u7edf\u9ed8\u8ba4\u7684C\u5e93\uff0c\u63d0\u4f9b\u4e86\u7cfb\u7edf\u8c03\u7528\u548c\u57fa\u672c\u529f\u80fd\u5982\u8f93\u5165\/\u8f93\u51fa\u5904\u7406\u3002<\/li>\n\n\n\n<li>libm\uff1a\u8fd9\u662f\u4e00\u4e2a\u6570\u5b66\u5e93\uff0c\u63d0\u4f9b\u4e86\u8bb8\u591a\u6570\u5b66\u51fd\u6570\u7684\u5b9e\u73b0\u3002<\/li>\n\n\n\n<li>libpthread\uff1a\u8fd9\u662f\u7ebf\u7a0b\u7f16\u7a0b\u5e93\uff0c\u63d0\u4f9b\u4e86POSIX\u7ebf\u7a0b\u7f16\u7a0b\u7684API\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:#fcb900\" class=\"has-inline-color\">\u7b2c\u4e09\u65b9\u5e93\uff1a<\/mark><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>OpenSSL\uff1a\u8fd9\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5b89\u5168\u5957\u63a5\u5b57\u5c42\u5bc6\u7801\u5e93\uff0c\u5305\u62ec\u4e3b\u8981\u7684\u5bc6\u7801\u7b97\u6cd5\u3001\u5e38\u7528\u7684\u5bc6\u94a5\u548c\u8bc1\u4e66\u5c01\u88c5\u7ba1\u7406\u529f\u80fd\u4ee5\u53caSSL\u534f\u8bae\uff0c\u5e76\u63d0\u4f9b\u4e30\u5bcc\u7684\u5e94\u7528\u7a0b\u5e8f\u4f9b\u6d4b\u8bd5\u6216\u5176\u5b83\u76ee\u7684\u4f7f\u7528\u3002<\/li>\n\n\n\n<li>libcurl\uff1a\u8fd9\u662f\u4e00\u4e2a\u514d\u8d39\u7684\u3001\u6613\u7528\u7684URL\u8bed\u6cd5\u5e93\uff0c\u652f\u6301DICT\u3001FILE\u3001FTP\u3001FTPS\u3001GOPHER\u3001HTTP\u3001HTTPS\u3001IMAP\u3001IMAPS\u3001LDAP\u3001LDAPS\u3001POP3\u3001POP3S\u3001RTMP\u3001RTSP\u3001SCP\u3001SFTP\u3001SMTP\u3001SMTPS\u3001TELNET\u548cTFTP\u7b49\u534f\u8bae\u3002<\/li>\n\n\n\n<li>libpng\uff1a\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u5904\u7406PNG\u56fe\u50cf\u7684\u5e93\u3002<\/li>\n\n\n\n<li>libjpeg\uff1a\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u5904\u7406JPEG\u56fe\u50cf\u7684\u5e93\u3002<\/li>\n\n\n\n<li>freetype\uff1a\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u6e32\u67d3\u5b57\u4f53\u5230\u4f4d\u56fe\u7684\u5e93\uff0c\u652f\u6301\u591a\u79cd\u5b57\u4f53\u683c\u5f0f\u3002<\/li>\n\n\n\n<li>zlib\uff1a\u8fd9\u662f\u4e00\u4e2a\u538b\u7f29\u548c\u89e3\u538b\u7f29\u5e93\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\">\u53ef\u62d3\u5c55\u65b9\u5411<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">ABI\u2014\u2014\u5168\u79f0\u4e3aApplication Binary Interface\uff0c\u5373\u5e94\u7528\u7a0b\u5e8f\u4e8c\u8fdb\u5236\u63a5\u53e3\u3002\u5b83\u5b9a\u4e49\u4e86\u5728\u540c\u4e00\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u548c\u7cfb\u7edf\u4e4b\u95f4\u6216\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\u4e4b\u95f4\u7684\u4f4e\u7ea7\u63a5\u53e3<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u7684\u4e8c\u8fdb\u5236\u690d\u5165\u653b\u51fb<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u653b\u51fb\u8005\u63a7\u5236\u8f6f\u4ef6\u4e2d\u7684\u67d0\u4e2a\u52a8\u6001\u5e93\u641c\u7d22\u8def\u5f84\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u9488\u5bf9\u7a0b\u5e8f\u7684\u63a5\u53e3\u8fdb\u884c\u6076\u610f\u4ee3\u7801\u7684\u7f16\u5199\u66ff\u6362\uff0c\u7136\u540e\u5bf9\u8f6f\u4ef6\u8fdb\u884c\u653b\u51fb\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9884\u9632\u7684\u65b9\u6cd5\u4e5f\u6709\u5f88\u591a\uff0c\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u4f7f\u7528\u6570\u5b57\u7b7e\u540d\u9a8c\u8bc1\u52a8\u6001\u7684\u5b89\u5168\u6027\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528 chroot \u73af\u5883<\/strong>\uff1achroot \u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u9694\u79bb\u7684\u73af\u5883\uff0c\u4f7f\u5f97\u7a0b\u5e8f\u53ea\u80fd\u8bbf\u95ee\u8fd9\u4e2a\u73af\u5883\u4e2d\u7684\u6587\u4ef6\u548c\u76ee\u5f55\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u9632\u6b62\u7a0b\u5e8f\u52a0\u8f7d\u5230 chroot \u73af\u5883\u5916\u90e8\u7684\u6076\u610f\u52a8\u6001\u5e93\u3002<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u52a8\u6001\u5e93\u4ee3\u7801\u5171\u540c\u51b2\u7a81\u95ee\u9898<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u591a\u4e2a\u7a0b\u5e8f\u540c\u65f6\u8c03\u7528\u540c\u4e00\u4e2a\u52a8\u6001\u5e93\u4e2d\u7684\u540c\u4e00\u4e2a\u53d8\u91cf\u65f6\uff0c\u901a\u5e38\u4e0d\u4f1a\u51fa\u73b0\u51b2\u7a81\u3002\u8fd9\u662f\u56e0\u4e3a\u6bcf\u4e2a\u7a0b\u5e8f\u90fd\u6709\u81ea\u5df1\u7684\u5730\u5740\u7a7a\u95f4\uff0c\u7a0b\u5e8f\u4e2d\u7684\u5168\u5c40\u53d8\u91cf\u548c\u9759\u6001\u53d8\u91cf\u90fd\u5b58\u50a8\u5728\u7a0b\u5e8f\u81ea\u5df1\u7684\u5730\u5740\u7a7a\u95f4\u4e2d\uff0c\u4e0d\u4f1a\u4e0e\u5176\u4ed6\u7a0b\u5e8f\u7684\u53d8\u91cf\u51b2\u7a81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9759\u6001\u5e93(Static Link Library) \u9759\u6001\u5e93\u7684\u6982\u5ff5\u548c\u4f5c\u7528 \u9759\u6001\u5e93\u7684\u6982\u5ff5 \u9759\u6001\u5e93\u662f\u4e00\u79cd\u5305\u542b\u4e86\u591a\u4e2a\u5bf9\u8c61 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[17,18,33,38,29],"class_list":["post-930","post","type-post","status-publish","format-standard","hentry","category-c-c","category-learning","tag-c-2","tag-c","tag-linux","tag-38","tag-library_function"],"_links":{"self":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/comments?post=930"}],"version-history":[{"count":23,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/930\/revisions"}],"predecessor-version":[{"id":969,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/posts\/930\/revisions\/969"}],"wp:attachment":[{"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/media?parent=930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/categories?post=930"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.chxzking.cn\/index.php\/wp-json\/wp\/v2\/tags?post=930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}