{"id":56856,"date":"2025-08-14T23:54:40","date_gmt":"2025-08-14T15:54:40","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/56856.html"},"modified":"2025-08-14T23:54:40","modified_gmt":"2025-08-14T15:54:40","slug":"c%e6%ba%90%e6%96%87%e4%bb%b6%e5%88%b0%e5%8f%af%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f%e7%9a%84%e8%af%a6%e7%bb%86%e8%bf%87%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/56856.html","title":{"rendered":"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b"},"content":{"rendered":"<h2>1. \u6982\u89c8<\/h2>\n<p>\u7f16\u8bd1\u5c31\u662f\u5c06C&#043;&#043;\u6e90\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u53ef\u4ee5\u7406\u89e3\u7684\u683c\u5f0f\u7684\u4e00\u4e2a\u8fc7\u7a0b\u3002\u5bf9\u4e8e\u8ba1\u7b97\u673a\u6765\u8bf4&#xff0c;\u5b83\u53ea\u80fd\u7406\u89e3\u4e8c\u8fdb\u5236\u7f16\u7801&#xff0c;C&#043;&#043;\u7684\u6e90\u4ee3\u7801\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u4eba\u7c7b\u7406\u89e3(human-readable)\u3002\u6240\u4ee5, \u4e3a\u4e86\u8ba9\u673a\u5668\u7406\u89e3\u6211\u4eec\u7684\u4ee3\u7801&#xff0c;\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u201c\u7ffb\u8bd1\u5b98\u201d&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684\u7f16\u8bd1\u5668(Compiler), \u7f16\u8bd1\u5668\u7684\u5de5\u4f5c\u5c31\u662f\u5c06\u6e90\u4ee3\u7801\u8f6c\u6362\u673a\u5668\u8bed\u8a00&#xff0c;\u7f16\u8bd1\u7684\u8fc7\u7a0b\u4e5f\u5c31\u662f\u4e00\u4e2a\u201c\u7ffb\u8bd1\u201d\u7684\u8fc7\u7a0b. \u4e00\u4e2a\u5b8c\u6574\u7684\u7f16\u8bd1\u8fc7\u7a0b\u4e3b\u8981\u5206\u4e3a\u4ee5\u4e0b\u56db\u4e2a\u9636\u6bb5&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u6b65\u9aa4\u540d\u79f0\u8f93\u5165\u4e3b\u8981\u5904\u7406\u5185\u5bb9\u8f93\u51fa<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u9884\u5904\u7406(Preprocessing)<\/td>\n<td>C\/C&#043;&#043; \u6e90\u6587\u4ef6(.c\/.cpp, .h\/.hpp)<\/td>\n<td>\u79fb\u9664\u6ce8\u91ca\u3001\u5c55\u5f00\u5b8f\u3001\u5904\u7406 #include\u3001\u6267\u884c\u6761\u4ef6\u7f16\u8bd1&#xff0c;\u751f\u6210\u65e0\u9884\u5904\u7406\u6307\u4ee4\u7684\u6e90\u7801<\/td>\n<td>\u9884\u5904\u7406\u6587\u4ef6(.i \/ .ii)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u7f16\u8bd1(Compilation)<\/td>\n<td>\u9884\u5904\u7406\u6587\u4ef6(.i \/ .ii)<\/td>\n<td>\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\u3001\u4f18\u5316\u4ee3\u7801&#xff0c;\u751f\u6210\u5bf9\u5e94\u7684\u6c47\u7f16\u4ee3\u7801<\/td>\n<td>\u6c47\u7f16\u6587\u4ef6(.s \/ .asm)<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u6c47\u7f16(Assembly)<\/td>\n<td>\u6c47\u7f16\u6587\u4ef6(.s \/ .asm)<\/td>\n<td>\u5c06\u6c47\u7f16\u6307\u4ee4\u7ffb\u8bd1\u4e3a\u673a\u5668\u7801&#xff0c;\u751f\u6210\u53ef\u91cd\u5b9a\u4f4d\u7684\u76ee\u6807\u6587\u4ef6<\/td>\n<td>\u76ee\u6807\u6587\u4ef6(.o \/ .obj)<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u94fe\u63a5(Linking)<\/td>\n<td>\u76ee\u6807\u6587\u4ef6\u4e0e\u5e93\u6587\u4ef6(.o \/ .obj, .lib \/ .a)<\/td>\n<td>\u5408\u5e76\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u4e0e\u5e93&#xff0c;\u89e3\u51b3\u7b26\u53f7\u5f15\u7528&#xff0c;\u751f\u6210\u5b8c\u6574\u7684\u53ef\u6267\u884c\u7a0b\u5e8f<\/td>\n<td>\u53ef\u6267\u884c\u6587\u4ef6(.exe \/ a.out)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Compilation \u8fd9\u4e2a\u8bcd\u5728C&#043;&#043;\u8bed\u5883\u4e0b&#xff0c;\u65e2\u53ef\u4ee5\u6307\u4ee3\u4ece\u6e90\u4ee3\u7801\u5230\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6574\u4e2a\u5b8c\u6574\u8fc7\u7a0b&#xff0c;\u4e5f\u53ef\u4ee5\u7279\u6307\u5176\u4e2d\u201c\u5c06\u4ee3\u7801\u7ffb\u8bd1\u6210\u6c47\u7f16\u201d\u8fd9\u4e00\u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u8bf7\u6ce8\u610f\u533a\u5206\u3002<\/p>\n<h3>\u6d41\u7a0b\u56fe\u6982\u89c8<\/h3>\n<p>  #mermaid-svg-nYGP2JpoeGGVzh5R {font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .error-icon{fill:#552222;}#mermaid-svg-nYGP2JpoeGGVzh5R .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-nYGP2JpoeGGVzh5R .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-nYGP2JpoeGGVzh5R .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-nYGP2JpoeGGVzh5R .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-nYGP2JpoeGGVzh5R .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-nYGP2JpoeGGVzh5R .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-nYGP2JpoeGGVzh5R .marker{fill:#333333;stroke:#333333;}#mermaid-svg-nYGP2JpoeGGVzh5R .marker.cross{stroke:#333333;}#mermaid-svg-nYGP2JpoeGGVzh5R svg{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-nYGP2JpoeGGVzh5R .label{font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;color:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .cluster-label text{fill:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .cluster-label span{color:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .label text,#mermaid-svg-nYGP2JpoeGGVzh5R span{fill:#333;color:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .node rect,#mermaid-svg-nYGP2JpoeGGVzh5R .node circle,#mermaid-svg-nYGP2JpoeGGVzh5R .node ellipse,#mermaid-svg-nYGP2JpoeGGVzh5R .node polygon,#mermaid-svg-nYGP2JpoeGGVzh5R .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-nYGP2JpoeGGVzh5R .node .label{text-align:center;}#mermaid-svg-nYGP2JpoeGGVzh5R .node.clickable{cursor:pointer;}#mermaid-svg-nYGP2JpoeGGVzh5R .arrowheadPath{fill:#333333;}#mermaid-svg-nYGP2JpoeGGVzh5R .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-nYGP2JpoeGGVzh5R .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-nYGP2JpoeGGVzh5R .edgeLabel{background-color:#e8e8e8;text-align:center;}#mermaid-svg-nYGP2JpoeGGVzh5R .edgeLabel rect{opacity:0.5;background-color:#e8e8e8;fill:#e8e8e8;}#mermaid-svg-nYGP2JpoeGGVzh5R .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-nYGP2JpoeGGVzh5R .cluster text{fill:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R .cluster span{color:#333;}#mermaid-svg-nYGP2JpoeGGVzh5R div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-nYGP2JpoeGGVzh5R :root{&#8211;mermaid-font-family:\\&#8221;trebuchet ms\\&#8221;,verdana,arial,sans-serif;}<\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"edgeLabel\"><\/span><\/p>\n<p>         <span class=\"nodeLabel\">&#x1f4bb; \u6e90\u4ee3\u7801(main.cpp)<\/span><\/p>\n<p>         <span class=\"nodeLabel\">&#x1f4dd; \u9884\u5904\u7406\u5c55\u5f00\u5b8f\/\u5305\u542b\u5934\u6587\u4ef6\/\u79fb\u9664\u6ce8\u91ca\u4ea7\u7269&#xff1a;main.i<\/span><\/p>\n<p>         <span class=\"nodeLabel\">\u2699\ufe0f \u7f16\u8bd1\u8bcd\u6cd5&#043;\u8bed\u6cd5&#043;\u8bed\u4e49\u5206\u6790 \u2192 \u751f\u6210\u6c47\u7f16\u4ea7\u7269&#xff1a;main.s<\/span><\/p>\n<p>         <span class=\"nodeLabel\">&#x1f528; \u6c47\u7f16\u6c47\u7f16\u4ee3\u7801 \u2192 \u673a\u5668\u7801\u4ea7\u7269&#xff1a;main.o<\/span><\/p>\n<p>         <span class=\"nodeLabel\">&#x1f517; \u94fe\u63a5\u7b26\u53f7\u89e3\u6790&#043;\u5730\u5740\u5206\u914d \u2192 \u53ef\u6267\u884c\u6587\u4ef6\u4ea7\u7269&#xff1a;main<\/span><\/p>\n<p>         <span class=\"nodeLabel\">\u25b6\ufe0f \u8fd0\u884c\u7a0b\u5e8f\u8f93\u51fa&#xff1a;Hello, World!<\/span><\/p>\n<h2>2. \u7f16\u8bd1\u8fc7\u7a0b\u8be6\u89e3<\/h2>\n<h3>2.1 \u9884\u5904\u7406&#xff08;Preprocessing&#xff09;<\/h3>\n<p>\u7f16\u8bd1\u8fc7\u7a0b\u7684\u7b2c\u4e00\u9636\u6bb5&#xff0c;\u4e3b\u8981\u5305\u542b\u4e86\u4ee5\u4e0b\u52a8\u4f5c&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u6b65\u9aa4\u4e3b\u8981\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>Comments removal<\/td>\n<td>\u5220\u9664 \/\/ \u548c \/*&#8230;*\/ \u4e2d\u7684\u6ce8\u91ca\u5185\u5bb9&#xff0c;\u53ea\u4fdd\u7559\u6709\u6548\u4ee3\u7801<\/td>\n<td>int a&#061;1; \/\/ \u53d8\u91cf \u2192 int a&#061;1;<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>Macros expansion<\/td>\n<td>\u5c06 #define \u5b9a\u4e49\u7684\u5b8f\u66ff\u6362\u4e3a\u5b9e\u9645\u5185\u5bb9<\/td>\n<td>#define PI 3.14 \u2192 area&#061;3.14*r*r;<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>File inclusion<\/td>\n<td>\u5c06 #include \u5f15\u7528\u7684\u5934\u6587\u4ef6\u5185\u5bb9\u76f4\u63a5\u63d2\u5165\u5230\u4ee3\u7801\u4e2d<\/td>\n<td>#include &lt;stdio.h&gt; \u2192 \u63d2\u5165 stdio.h \u6587\u4ef6\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>Conditional compilation<\/td>\n<td>\u6839\u636e\u6761\u4ef6\u6307\u4ee4\u9009\u62e9\u6027\u4fdd\u7559\u6216\u5220\u9664\u4ee3\u7801<\/td>\n<td>#ifdef DEBUG \u5305\u542b\u8c03\u8bd5\u4ee3\u7801&#xff0c;\u5426\u5219\u79fb\u9664<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.2 \u7f16\u8bd1(Complication)<\/h3>\n<p>\u7f16\u8bd1\u9636\u6bb5\u7684\u6838\u5fc3\u4efb\u52a1\u662f\u5c06\u9884\u5904\u7406\u540e\u7684\u6e90\u4ee3\u7801\u7ffb\u8bd1\u6210\u6c47\u7f16\u4ee3\u7801\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d&#xff0c;\u7f16\u8bd1\u5668\u4e0d\u4ec5\u4f1a\u68c0\u67e5\u4ee3\u7801\u7684\u6b63\u786e\u6027&#xff0c;\u8fd8\u4f1a\u8fdb\u884c\u4f18\u5316&#xff0c;\u4ee5\u4fbf\u751f\u6210\u9ad8\u6548\u7684\u76ee\u6807\u7a0b\u5e8f\u3002\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u6b65\u9aa4\u4e3b\u8981\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u8bcd\u6cd5\u5206\u6790<\/td>\n<td>\u5c06\u6e90\u7801\u62c6\u5206\u4e3a\u8bcd\u6cd5\u5355\u5143&#xff08;Token&#xff09;&#xff0c;\u5982\u5173\u952e\u5b57\u3001\u6807\u8bc6\u7b26\u3001\u5e38\u91cf\u3001\u8fd0\u7b97\u7b26\u7b49<\/td>\n<td>int a&#061;5; \u2192 int\u3001a\u3001&#061;\u30015\u3001;<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u8bed\u6cd5\u5206\u6790<\/td>\n<td>\u6839\u636e\u8bed\u6cd5\u89c4\u5219\u5c06 Token \u7ec4\u7ec7\u6210\u8bed\u6cd5\u6811&#xff08;AST&#xff09;&#xff0c;\u5e76\u68c0\u6d4b\u8bed\u6cd5\u5408\u6cd5\u6027<\/td>\n<td>\u68c0\u67e5 if(a&#061;&#061;5){} \u662f\u5426\u7b26\u5408 C&#043;&#043; \u6807\u51c6\u8bed\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u8bed\u4e49\u5206\u6790<\/td>\n<td>\u786e\u4fdd\u7a0b\u5e8f\u8bed\u4e49\u6b63\u786e&#xff08;\u7c7b\u578b\u5339\u914d\u3001\u53d8\u91cf\u58f0\u660e\u3001\u4f5c\u7528\u57df\u7b49&#xff09;<\/td>\n<td>\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u5df2\u5b9a\u4e49\u3001\u51fd\u6570\u8c03\u7528\u53c2\u6570\u7c7b\u578b\u662f\u5426\u5339\u914d<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u4e2d\u95f4\u4ee3\u7801\u751f\u6210<\/td>\n<td>\u5c06 AST \u8f6c\u6362\u4e3a\u5e73\u53f0\u65e0\u5173\u7684\u4e2d\u95f4\u8868\u793a&#xff08;IR&#xff09;<\/td>\n<td>\u751f\u6210 LLVM IR \/ GCC GIMPLE<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>\u4ee3\u7801\u4f18\u5316<\/td>\n<td>\u5bf9 IR \u8fdb\u884c\u4f18\u5316&#xff08;\u5220\u9664\u5197\u4f59\u3001\u5faa\u73af\u4f18\u5316\u3001\u51fd\u6570\u5185\u8054\u7b49&#xff09;<\/td>\n<td>\u5c06 x &#061; x &#043; 0 \u4f18\u5316\u6389<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>\u6c47\u7f16\u4ee3\u7801\u751f\u6210<\/td>\n<td>\u5c06\u4f18\u5316\u540e\u7684 IR \u8f6c\u6362\u4e3a\u5bf9\u5e94 CPU \u67b6\u6784\u7684\u6c47\u7f16\u4ee3\u7801<\/td>\n<td>\u751f\u6210 .s \u6587\u4ef6&#xff0c;\u5982 mov eax,1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.3 \u6c47\u7f16&#xff08;Assembly&#xff09;<\/h3>\n<p>\u6c47\u7f16\u9636\u6bb5\u7684\u4efb\u52a1\u662f\u5c06\u6c47\u7f16\u4ee3\u7801\u7ffb\u8bd1\u6210\u673a\u5668\u6307\u4ee4&#xff0c;\u5e76\u751f\u6210\u53ef\u4f9b\u94fe\u63a5\u5668\u5904\u7406\u7684\u76ee\u6807\u6587\u4ef6\u3002\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u6b65\u9aa4\u4e3b\u8981\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u6307\u4ee4\u7ffb\u8bd1<\/td>\n<td>\u5c06\u6c47\u7f16\u6307\u4ee4\u8f6c\u5316\u4e3a CPU \u53ef\u8bc6\u522b\u7684\u673a\u5668\u7801<\/td>\n<td>mov eax,1 \u2192 B8 01 00 00 00<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u7b26\u53f7\u8bb0\u5f55<\/td>\n<td>\u5728\u76ee\u6807\u6587\u4ef6\u4e2d\u4fdd\u5b58\u51fd\u6570\u3001\u53d8\u91cf\u7b49\u7b26\u53f7\u7684\u5360\u4f4d\u7b26&#xff0c;\u4ee5\u4f9b\u94fe\u63a5\u9636\u6bb5\u89e3\u6790<\/td>\n<td>printf \u5728\u7b26\u53f7\u8868\u4e2d\u7559\u4e0b\u672a\u89e3\u6790\u5f15\u7528<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u751f\u6210\u76ee\u6807\u6587\u4ef6<\/td>\n<td>\u8f93\u51fa .o&#xff08;Unix\/Linux&#xff09;\u6216 .obj&#xff08;Windows&#xff09;\u6587\u4ef6<\/td>\n<td>\u751f\u6210 main.o<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>2.4 \u94fe\u63a5(Linking)<\/h3>\n<p>\u94fe\u63a5\u9636\u6bb5\u4f1a\u5c06\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u4e0e\u6240\u9700\u7684\u5e93\u6587\u4ef6\u7ec4\u5408\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e0d\u4ec5\u89e3\u51b3\u7b26\u53f7\u5f15\u7528&#xff0c;\u8fd8\u4f1a\u5c06\u7a0b\u5e8f\u7684\u5404\u4e2a\u90e8\u5206\u6574\u5408\u4e3a\u4e00\u4e2a\u6574\u4f53\u3002\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b&#xff1a;<\/p>\n<table>\n<tr>\u9636\u6bb5\u6b65\u9aa4\u4e3b\u8981\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u7b26\u53f7\u89e3\u6790<\/td>\n<td>\u67e5\u627e\u5e76\u5339\u914d\u5404\u76ee\u6807\u6587\u4ef6\u548c\u5e93\u4e2d\u7684\u7b26\u53f7\u5f15\u7528\u4e0e\u5b9a\u4e49<\/td>\n<td>\u5728 libc \u4e2d\u627e\u5230 printf \u7684\u5b9e\u73b0<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u5730\u5740\u5206\u914d&#xff08;\u91cd\u5b9a\u4f4d&#xff09;<\/td>\n<td>\u4e3a\u4ee3\u7801\u548c\u6570\u636e\u5206\u914d\u6700\u7ec8\u5185\u5b58\u5730\u5740&#xff0c;\u5e76\u66ff\u6362\u5360\u4f4d\u7b26<\/td>\n<td>\u5c06 printf \u7684\u8c03\u7528\u5730\u5740\u66ff\u6362\u4e3a\u5b9e\u9645\u5730\u5740<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>\u5408\u5e76\u6bb5&#xff08;Sections&#xff09;<\/td>\n<td>\u5c06\u5404\u6587\u4ef6\u7684 .text&#xff08;\u4ee3\u7801\u6bb5&#xff09;\u3001.data&#xff08;\u6570\u636e\u6bb5&#xff09;\u7b49\u5408\u5e76<\/td>\n<td>\u5408\u5e76 main.o \u4e0e\u5e93\u6587\u4ef6\u7684\u4ee3\u7801\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6<\/td>\n<td>\u8f93\u51fa .exe&#xff08;Windows&#xff09;\u6216 a.out \/ ELF&#xff08;Unix\/Linux&#xff09;\u53ef\u76f4\u63a5\u8fd0\u884c\u7684\u7a0b\u5e8f<\/td>\n<td>\u751f\u6210 main.exe \u6216 a.out<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>ELF&#xff08;Executable and Linkable Format&#xff0c;\u53ef\u6267\u884c\u4e0e\u53ef\u94fe\u63a5\u683c\u5f0f&#xff09;\u662f\u4e00\u79cd\u7528\u4e8e\u53ef\u6267\u884c\u6587\u4ef6\u3001\u76ee\u6807\u4ee3\u7801\u3001\u5171\u4eab\u5e93\u548c\u6838\u5fc3\u8f6c\u50a8&#xff08;core dump&#xff09;\u7684\u6807\u51c6\u6587\u4ef6\u683c\u5f0f\u3002\u5b83\u662f\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf&#xff08;\u5982Linux\u3001Unix&#xff09;\u4e2d\u5e38\u89c1\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u683c\u5f0f&#xff0c;\u7528\u4e8e\u63cf\u8ff0\u7a0b\u5e8f\u7684\u5b58\u50a8\u7ed3\u6784\u548c\u52a0\u8f7d\u65b9\u5f0f &#xff0c;\u66f4\u591a\u5185\u5bb9\u8bf7\u67e5\u770bELF\u6587\u4ef6\u7ed3\u6784\u8be6\u89e3<\/p>\n<h2>3 \u52a8\u624b\u89c2\u5bdf<\/h2>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u5728 Ubuntu \u7cfb\u7edf\u4e2d\u89c2\u5bdf C\/C&#043;&#043; \u7a0b\u5e8f\u7f16\u8bd1\u5168\u6d41\u7a0b\u53ca\u4ea7\u7269\u7684\u5b8c\u6574\u64cd\u4f5c\u6b65\u9aa4&#xff0c;\u4f60\u53ef\u4ee5\u7528\u5b83\u5728\u81ea\u5df1\u7684\u673a\u5668\u4e0a\u5b9e\u9a8c\u6bcf\u4e00\u6b65&#xff1a;<\/p>\n<h3>3.1 \u521b\u5efa\u6e90\u6587\u4ef6<\/h3>\n<p>\u521b\u5efa\u4e00\u4e2amain.cpp&#xff0c;\u7f16\u8f91\u5185\u5bb9\u5982\u4e0b&#xff1a;<\/p>\n<p>\/\/ this is my test program<br \/>\n#include &lt;stdio.h&gt;<\/p>\n<p>int main() {<br \/>\n    printf(&#034;Hello, World!\\\\\\\\n&#034;);<br \/>\n    return 0;<br \/>\n}<\/p>\n<h3>3.2 \u9884\u5904\u7406<\/h3>\n<p>\u4f7f\u7528 g&#043;&#043; -E main.cpp -o main.i \u6a21\u62df\u8be5\u8fc7\u7a0b&#xff0c;\u8be5\u547d\u4ee4\u4f1a\u751f\u6210\u4e00\u4e2a main.i \u7684\u4ea7\u7269\u3002<\/p>\n<p>wayne&#064;server:~\/source\/temp$ ll<br \/>\ntotal <span class=\"token number\">12<\/span><br \/>\ndrwxrwxr-x <span class=\"token number\">2<\/span> wayne wayne <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 .\/<br \/>\ndrwxrwxr-x <span class=\"token number\">7<\/span> wayne wayne <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 <span class=\"token punctuation\">..<\/span>\/<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne   <span class=\"token number\">81<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:42 main.cpp<br \/>\nwayne&#064;server:~\/source\/temp$ g&#043;&#043; <span class=\"token parameter variable\">-E<\/span> main.cpp <span class=\"token parameter variable\">-o<\/span> main.i<br \/>\nwayne&#064;server:~\/source\/temp$ ll<br \/>\ntotal <span class=\"token number\">36<\/span><br \/>\ndrwxrwxr-x <span class=\"token number\">2<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 .\/<br \/>\ndrwxrwxr-x <span class=\"token number\">7<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 <span class=\"token punctuation\">..<\/span>\/<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne    <span class=\"token number\">81<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:42 main.cpp<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne <span class=\"token number\">20890<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 main.i<br \/>\nwayne&#064;server:~\/source\/temp$ <span class=\"token function\">cat<\/span> main.i<br \/>\n<span class=\"token comment\"># 0 &#034;main.cpp&#034;<\/span><br \/>\n<span class=\"token comment\"># 0 &#034;&lt;built-in&gt;&#034;<\/span><br \/>\n<span class=\"token comment\"># 0 &#034;&lt;command-line&gt;&#034;<\/span><br \/>\n<span class=\"token comment\"># 1 &#034;\/usr\/include\/stdc-predef.h&#034; 1 3 4<\/span><br \/>\n<span class=\"token comment\"># 0 &#034;&lt;command-line&gt;&#034; 2<\/span><br \/>\n<span class=\"token comment\"># 1 &#034;main.cpp&#034;<\/span><br \/>\n<span class=\"token comment\"># 1 &#034;\/usr\/include\/stdio.h&#034; 1 3 4<\/span><br \/>\n<span class=\"token comment\"># 27 &#034;\/usr\/include\/stdio.h&#034; 3 4<\/span><br \/>\n<span class=\"token comment\"># 1 &#034;\/usr\/include\/x86_64-linux-gnu\/bits\/libc-header-start.h&#034; 1 3 4<\/span><br \/>\n<span class=\"token comment\"># 33 &#034;\/usr\/include\/x86_64-linux-gnu\/bits\/libc-header-start.h&#034; 3 4<\/span><\/p>\n<h3>3.3 \u7f16\u8bd1<\/h3>\n<p>\u6267\u884c\u547d\u4ee4 g&#043;&#043; -S main.i -o main.s&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u6c47\u7f16\u4ee3\u7801\u4ea7\u7269 main.s\u3002<\/p>\n<p>wayne&#064;server:~\/source\/temp$ ll<br \/>\ntotal <span class=\"token number\">36<\/span><br \/>\ndrwxrwxr-x <span class=\"token number\">2<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:48 .\/<br \/>\ndrwxrwxr-x <span class=\"token number\">7<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 <span class=\"token punctuation\">..<\/span>\/<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne    <span class=\"token number\">81<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:42 main.cpp<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne <span class=\"token number\">20890<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 main.i<br \/>\nwayne&#064;server:~\/source\/temp$ g&#043;&#043; <span class=\"token parameter variable\">-S<\/span> main.i <span class=\"token parameter variable\">-o<\/span> main.s<br \/>\nwayne&#064;server:~\/source\/temp$ <span class=\"token function\">head<\/span> <span class=\"token parameter variable\">-n<\/span> <span class=\"token number\">20<\/span> main.s<br \/>\n        .file   <span class=\"token string\">&#034;main.cpp&#034;<\/span><br \/>\n        .text<br \/>\n        .section        .rodata<br \/>\n.LC0:<br \/>\n        .string <span class=\"token string\">&#034;Hello, World!<span class=\"token entity\" title=\"\\\\\\\\\">\\\\\\\\<\/span>n&#034;<\/span><br \/>\n        .text<br \/>\n        .globl  main<br \/>\n        .type   main, &#064;function<br \/>\nmain:<br \/>\n.LFB0:<br \/>\n        .cfi_startproc<br \/>\n        endbr64<br \/>\n        pushq   %rbp<br \/>\n        .cfi_def_cfa_offset <span class=\"token number\">16<\/span><br \/>\n        .cfi_offset <span class=\"token number\">6<\/span>, <span class=\"token parameter variable\">-16<\/span><br \/>\n        movq    %rsp, %rbp<br \/>\n        .cfi_def_cfa_register <span class=\"token number\">6<\/span><br \/>\n        leaq    .LC0<span class=\"token punctuation\">(<\/span>%rip<span class=\"token punctuation\">)<\/span>, %rax<br \/>\n        movq    %rax, %rdi<br \/>\n        movl    <span class=\"token variable\">$0<\/span>, %eax<br \/>\nwayne&#064;server:~\/source\/temp$ <\/p>\n<h3>3.4 \u6c47\u7f16<\/h3>\n<p>\u6267\u884c\u547d\u4ee4 g&#043;&#043; -o main.o -c main.s&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u6c47\u7f16\u4ee3\u7801\u4ea7\u7269 main.o\u3002<\/p>\n<p>\u5176\u4f59\u547d\u4ee4\u4ecb\u7ecd&#xff1a;<\/p>\n<p><span class=\"token function\">file<\/span> main.o     <span class=\"token comment\"># \u663e\u793a\u6587\u4ef6\u7c7b\u578b&#xff08;ELF 64-bit Relocatable object&#xff09;<\/span><br \/>\nhexdump <span class=\"token parameter variable\">-C<\/span> main.o <span class=\"token operator\">|<\/span> <span class=\"token function\">head<\/span>  <span class=\"token comment\"># \u67e5\u770b\u4e8c\u8fdb\u5236\u5185\u5bb9<\/span><br \/>\nreadelf <span class=\"token parameter variable\">-s<\/span> main.o         <span class=\"token comment\"># \u67e5\u770b\u7b26\u53f7\u8868<\/span><\/p>\n<p>\u64cd\u4f5c\u6f14\u793a<\/p>\n<p>wayne&#064;server:~\/source\/temp$ ll<br \/>\ntotal <span class=\"token number\">40<\/span><br \/>\ndrwxrwxr-x <span class=\"token number\">2<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:52 .\/<br \/>\ndrwxrwxr-x <span class=\"token number\">7<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 <span class=\"token punctuation\">..<\/span>\/<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne    <span class=\"token number\">81<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:42 main.cpp<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne <span class=\"token number\">20890<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 main.i<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne   <span class=\"token number\">687<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:48 main.s<br \/>\nwayne&#064;server:~\/source\/temp$ g&#043;&#043; <span class=\"token parameter variable\">-o<\/span> main.o <span class=\"token parameter variable\">-c<\/span> main.s<br \/>\nwayne&#064;server:~\/source\/temp$ <span class=\"token function\">file<\/span> main.o<br \/>\nmain.o: ELF <span class=\"token number\">64<\/span>-bit LSB relocatable, x86-64, version <span class=\"token number\">1<\/span> <span class=\"token punctuation\">(<\/span>SYSV<span class=\"token punctuation\">)<\/span>, not stripped<br \/>\nwayne&#064;server:~\/source\/temp$ hexdump <span class=\"token parameter variable\">-C<\/span> main.o <span class=\"token operator\">|<\/span> <span class=\"token function\">head<\/span><br \/>\n00000000  7f <span class=\"token number\">45<\/span> 4c <span class=\"token number\">46<\/span> 02 01 01 00  00 00 00 00 00 00 00 00  <span class=\"token operator\">|<\/span>.ELF<span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token operator\">|<\/span><br \/>\n00000010  01 00 3e 00 01 00 00 00  00 00 00 00 00 00 00 00  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">..<\/span><span class=\"token operator\">&gt;<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>.<span class=\"token operator\">|<\/span><br \/>\n00000020  00 00 00 00 00 00 00 00  <span class=\"token number\">60<\/span> 02 00 00 00 00 00 00  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>&#096;<span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>.<span class=\"token operator\">|<\/span><br \/>\n00000030  00 00 00 00 <span class=\"token number\">40<\/span> 00 00 00  00 00 <span class=\"token number\">40<\/span> 00 0e 00 0d 00  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>&#064;<span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>.&#064;<span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>.<span class=\"token operator\">|<\/span><br \/>\n00000040  f3 0f 1e fa <span class=\"token number\">55<\/span> <span class=\"token number\">48<\/span> <span class=\"token number\">89<\/span> e5  <span class=\"token number\">48<\/span> 8d 05 00 00 00 00 <span class=\"token number\">48<\/span>  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>UH<span class=\"token punctuation\">..<\/span>H<span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span>H<span class=\"token operator\">|<\/span><br \/>\n00000050  <span class=\"token number\">89<\/span> c7 b8 00 00 00 00 e8  00 00 00 00 b8 00 00 00  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token punctuation\">..<\/span><span class=\"token operator\">|<\/span><br \/>\n00000060  00 5d c3 <span class=\"token number\">48<\/span> <span class=\"token number\">65<\/span> 6c 6c 6f  2c <span class=\"token number\">20<\/span> <span class=\"token number\">57<\/span> 6f <span class=\"token number\">72<\/span> 6c <span class=\"token number\">64<\/span> <span class=\"token number\">21<\/span>  <span class=\"token operator\">|<\/span>.<span class=\"token punctuation\">]<\/span>.Hello, World<span class=\"token operator\">!<\/span><span class=\"token operator\">|<\/span><br \/>\n00000070  5c 6e 00 00 <span class=\"token number\">47<\/span> <span class=\"token number\">43<\/span> <span class=\"token number\">43<\/span> 3a  <span class=\"token number\">20<\/span> <span class=\"token number\">28<\/span> <span class=\"token number\">55<\/span> <span class=\"token number\">62<\/span> <span class=\"token number\">75<\/span> 6e <span class=\"token number\">74<\/span> <span class=\"token number\">75<\/span>  <span class=\"token operator\">|<\/span><span class=\"token punctuation\">\\\\<\/span>n<span class=\"token punctuation\">..<\/span>GCC: <span class=\"token punctuation\">(<\/span>Ubuntu<span class=\"token operator\">|<\/span><br \/>\n00000080  <span class=\"token number\">20<\/span> <span class=\"token number\">31<\/span> <span class=\"token number\">31<\/span> 2e <span class=\"token number\">34<\/span> 2e <span class=\"token number\">30<\/span> 2d  <span class=\"token number\">31<\/span> <span class=\"token number\">75<\/span> <span class=\"token number\">62<\/span> <span class=\"token number\">75<\/span> 6e <span class=\"token number\">74<\/span> <span class=\"token number\">75<\/span> <span class=\"token number\">31<\/span>  <span class=\"token operator\">|<\/span> <span class=\"token number\">11.4<\/span>.0-1ubuntu1<span class=\"token operator\">|<\/span><br \/>\n00000090  7e <span class=\"token number\">32<\/span> <span class=\"token number\">32<\/span> 2e <span class=\"token number\">30<\/span> <span class=\"token number\">34<\/span> <span class=\"token number\">29<\/span> <span class=\"token number\">20<\/span>  <span class=\"token number\">31<\/span> <span class=\"token number\">31<\/span> 2e <span class=\"token number\">34<\/span> 2e <span class=\"token number\">30<\/span> 00 00  <span class=\"token operator\">|<\/span>~22.04<span class=\"token punctuation\">)<\/span> <span class=\"token number\">11.4<\/span>.0<span class=\"token punctuation\">..<\/span><span class=\"token operator\">|<\/span><br \/>\nwayne&#064;server:~\/source\/temp$ readelf <span class=\"token parameter variable\">-s<\/span> main.o <\/p>\n<p>Symbol table <span class=\"token string\">&#039;.symtab&#039;<\/span> contains <span class=\"token number\">6<\/span> entries:<br \/>\n   Num:    Value          Size Type    Bind   Vis      Ndx Name<br \/>\n     <span class=\"token number\">0<\/span>: 0000000000000000     <span class=\"token number\">0<\/span> NOTYPE  LOCAL  DEFAULT  UND<br \/>\n     <span class=\"token number\">1<\/span>: 0000000000000000     <span class=\"token number\">0<\/span> FILE    LOCAL  DEFAULT  ABS main.cpp<br \/>\n     <span class=\"token number\">2<\/span>: 0000000000000000     <span class=\"token number\">0<\/span> SECTION LOCAL  DEFAULT    <span class=\"token number\">1<\/span> .text<br \/>\n     <span class=\"token number\">3<\/span>: 0000000000000000     <span class=\"token number\">0<\/span> SECTION LOCAL  DEFAULT    <span class=\"token number\">5<\/span> .rodata<br \/>\n     <span class=\"token number\">4<\/span>: 0000000000000000    <span class=\"token number\">35<\/span> FUNC    GLOBAL DEFAULT    <span class=\"token number\">1<\/span> main<br \/>\n     <span class=\"token number\">5<\/span>: 0000000000000000     <span class=\"token number\">0<\/span> NOTYPE  GLOBAL DEFAULT  UND <span class=\"token builtin class-name\">printf<\/span><br \/>\nwayne&#064;server:~\/source\/temp$ <\/p>\n<h3>3.5 \u94fe\u63a5&#xff08;\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6&#xff09;<\/h3>\n<p>\u6267\u884c\u547d\u4ee4 g&#043;&#043; main.o -o main&#xff0c; \u5f97\u5230\u6700\u7ec8\u7684\u53ef\u6267\u884c\u6587\u4ef6, \u6587\u4ef6\u683c\u5f0f\u4e3aelf\u7c7b\u578b(linux\u4e0a\u7684\u53ef\u6267\u884c\u6587\u4ef6\u683c\u5f0f) \u5176\u4f59\u547d\u4ee4\u4ecb\u7ecd&#xff1a;<\/p>\n<p><span class=\"token function\">file<\/span> main     <span class=\"token comment\"># \u663e\u793a\u4e3a ELF 64-bit LSB executable<\/span><br \/>\nreadelf <span class=\"token parameter variable\">-h<\/span> main  <span class=\"token comment\"># \u67e5\u770b ELF \u6587\u4ef6\u5934<\/span><\/p>\n<p>\u5b9e\u9645\u64cd\u4f5c\u6f14\u793a&#xff1a;<\/p>\n<p>wayne&#064;server:~\/source\/temp$ ll<br \/>\ntotal <span class=\"token number\">44<\/span><br \/>\ndrwxrwxr-x <span class=\"token number\">2<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:52 .\/<br \/>\ndrwxrwxr-x <span class=\"token number\">7<\/span> wayne wayne  <span class=\"token number\">4096<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 <span class=\"token punctuation\">..<\/span>\/<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne    <span class=\"token number\">81<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:42 main.cpp<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne <span class=\"token number\">20890<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:43 main.i<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne  <span class=\"token number\">1504<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:52 main.o<br \/>\n-rw-rw-r&#8211; <span class=\"token number\">1<\/span> wayne wayne   <span class=\"token number\">687<\/span> Aug <span class=\"token number\">10<\/span> <span class=\"token number\">11<\/span>:48 main.s<br \/>\nwayne&#064;server:~\/source\/temp$ g&#043;&#043; main.o <span class=\"token parameter variable\">-o<\/span> main<br \/>\nwayne&#064;server:~\/source\/temp$ <span class=\"token function\">file<\/span> main<br \/>\nmain: ELF <span class=\"token number\">64<\/span>-bit LSB pie executable, x86-64, version <span class=\"token number\">1<\/span> <span class=\"token punctuation\">(<\/span>SYSV<span class=\"token punctuation\">)<\/span>, dynamically linked, interpreter \/lib64\/ld-linux-x86-64.so.2, BuildID<span class=\"token punctuation\">[<\/span>sha1<span class=\"token punctuation\">]<\/span><span class=\"token operator\">&#061;<\/span>fc45d54bd23fe46646071b84ab26edd4acc85693, <span class=\"token keyword\">for<\/span> GNU\/Linux <span class=\"token number\">3.2<\/span>.0, not stripped<br \/>\nwayne&#064;server:~\/source\/temp$ readelf <span class=\"token parameter variable\">-h<\/span> main<br \/>\nELF Header:<br \/>\n  Magic:   7f <span class=\"token number\">45<\/span> 4c <span class=\"token number\">46<\/span> 02 01 01 00 00 00 00 00 00 00 00 00<br \/>\n  Class:                             ELF64<br \/>\n  Data:                              <span class=\"token number\">2<\/span>&#039;s complement, little endian<br \/>\n  Version:                           <span class=\"token number\">1<\/span> <span class=\"token punctuation\">(<\/span>current<span class=\"token punctuation\">)<\/span><br \/>\n  OS\/ABI:                            UNIX &#8211; System V<br \/>\n  ABI Version:                       <span class=\"token number\">0<\/span><br \/>\n  Type:                              DYN <span class=\"token punctuation\">(<\/span>Position-Independent Executable <span class=\"token function\">file<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  Machine:                           Advanced Micro Devices X86-64<br \/>\n  Version:                           0x1<br \/>\n  Entry point address:               0x1060<br \/>\n  Start of program headers:          <span class=\"token number\">64<\/span> <span class=\"token punctuation\">(<\/span>bytes into <span class=\"token function\">file<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  Start of section headers:          <span class=\"token number\">13976<\/span> <span class=\"token punctuation\">(<\/span>bytes into <span class=\"token function\">file<\/span><span class=\"token punctuation\">)<\/span><br \/>\n  Flags:                             0x0<br \/>\n  Size of this header:               <span class=\"token number\">64<\/span> <span class=\"token punctuation\">(<\/span>bytes<span class=\"token punctuation\">)<\/span><br \/>\n  Size of program headers:           <span class=\"token number\">56<\/span> <span class=\"token punctuation\">(<\/span>bytes<span class=\"token punctuation\">)<\/span><br \/>\n  Number of program headers:         <span class=\"token number\">13<\/span><br \/>\n  Size of section headers:           <span class=\"token number\">64<\/span> <span class=\"token punctuation\">(<\/span>bytes<span class=\"token punctuation\">)<\/span><br \/>\n  Number of section headers:         <span class=\"token number\">31<\/span><br \/>\n  Section header string table index: <span class=\"token number\">30<\/span><br \/>\nwayne&#064;server:~\/source\/temp$ <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb177\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf2\u6b21\u3002C++\u7f16\u8bd1\u8fc7\u7a0b\u8be6\u89e3 C++\u7f16\u8bd1\u662f\u4e00\u4e2a\u5c06\u4eba\u7c7b\u53ef\u8bfb\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u4e3b\u8981\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff1a \u9884\u5904\u7406\u9636\u6bb5\uff1a\u5904\u7406\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u3001\u5934\u6587\u4ef6\u5305\u542b\u548c\u6761\u4ef6\u7f16\u8bd1\u6307\u4ee4\uff0c\u751f\u6210\u7eafC++\u4ee3\u7801\u6587\u4ef6\uff08.i\/.ii\uff09 \u7f16\u8bd1\u9636\u6bb5\uff1a\u8fdb\u884c\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\uff0c\u751f\u6210\u4e2d\u95f4\u4ee3\u7801\u5e76\u4f18\u5316\uff0c\u6700\u7ec8\u8f93\u51fa\u6c47\u7f16\u4ee3\u7801\uff08.s\uff09 \u6c47\u7f16\u9636\u6bb5\uff1a\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u6307\u4ee4\uff0c\u751f\u6210\u4e8c\u8fdb\u5236\u76ee\u6807\u6587\u4ef6\uff08.o\/.obj\uff09 \u94fe\u63a5\u9636\u6bb5\uff1a\u5408\u5e76\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\uff0c\u89e3\u6790\u7b26\u53f7\u5f15\u7528\uff0c\u751f\u6210\u6700\u7ec8\u53ef\u6267\u884c\u7a0b\u5e8f \u6bcf\u4e2a\u9636\u6bb5\u90fd\u6709\u7279\u5b9a\u7684\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u901a\u8fc7GCC\u7b49\u7f16\u8bd1\u5668\u5de5\u5177\u94fe\u53ef\u4ee5\u9010\u6b65\u89c2\u5bdf\u8fd9\u4e00\u8f6c\u6362\u8fc7\u7a0b\u3002\u7406<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[55],"topic":[],"class_list":["post-56856","post","type-post","status-publish","format-standard","hentry","category-server","tag-c"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/56856.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb177\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf2\u6b21\u3002C++\u7f16\u8bd1\u8fc7\u7a0b\u8be6\u89e3 C++\u7f16\u8bd1\u662f\u4e00\u4e2a\u5c06\u4eba\u7c7b\u53ef\u8bfb\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u4e3b\u8981\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff1a \u9884\u5904\u7406\u9636\u6bb5\uff1a\u5904\u7406\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u3001\u5934\u6587\u4ef6\u5305\u542b\u548c\u6761\u4ef6\u7f16\u8bd1\u6307\u4ee4\uff0c\u751f\u6210\u7eafC++\u4ee3\u7801\u6587\u4ef6\uff08.i\/.ii\uff09 \u7f16\u8bd1\u9636\u6bb5\uff1a\u8fdb\u884c\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\uff0c\u751f\u6210\u4e2d\u95f4\u4ee3\u7801\u5e76\u4f18\u5316\uff0c\u6700\u7ec8\u8f93\u51fa\u6c47\u7f16\u4ee3\u7801\uff08.s\uff09 \u6c47\u7f16\u9636\u6bb5\uff1a\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u6307\u4ee4\uff0c\u751f\u6210\u4e8c\u8fdb\u5236\u76ee\u6807\u6587\u4ef6\uff08.o\/.obj\uff09 \u94fe\u63a5\u9636\u6bb5\uff1a\u5408\u5e76\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\uff0c\u89e3\u6790\u7b26\u53f7\u5f15\u7528\uff0c\u751f\u6210\u6700\u7ec8\u53ef\u6267\u884c\u7a0b\u5e8f \u6bcf\u4e2a\u9636\u6bb5\u90fd\u6709\u7279\u5b9a\u7684\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u901a\u8fc7GCC\u7b49\u7f16\u8bd1\u5668\u5de5\u5177\u94fe\u53ef\u4ee5\u9010\u6b65\u89c2\u5bdf\u8fd9\u4e00\u8f6c\u6362\u8fc7\u7a0b\u3002\u7406\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/56856.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-08-14T15:54:40+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/56856.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/56856.html\",\"name\":\"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-08-14T15:54:40+00:00\",\"dateModified\":\"2025-08-14T15:54:40+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/56856.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/56856.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/56856.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/56856.html","og_locale":"zh_CN","og_type":"article","og_title":"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb177\u6b21\uff0c\u70b9\u8d5e3\u6b21\uff0c\u6536\u85cf2\u6b21\u3002C++\u7f16\u8bd1\u8fc7\u7a0b\u8be6\u89e3 C++\u7f16\u8bd1\u662f\u4e00\u4e2a\u5c06\u4eba\u7c7b\u53ef\u8bfb\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u5b8c\u6574\u6d41\u7a0b\uff0c\u4e3b\u8981\u5206\u4e3a\u56db\u4e2a\u9636\u6bb5\uff1a \u9884\u5904\u7406\u9636\u6bb5\uff1a\u5904\u7406\u6e90\u4ee3\u7801\u4e2d\u7684\u5b8f\u3001\u5934\u6587\u4ef6\u5305\u542b\u548c\u6761\u4ef6\u7f16\u8bd1\u6307\u4ee4\uff0c\u751f\u6210\u7eafC++\u4ee3\u7801\u6587\u4ef6\uff08.i\/.ii\uff09 \u7f16\u8bd1\u9636\u6bb5\uff1a\u8fdb\u884c\u8bcd\u6cd5\u5206\u6790\u3001\u8bed\u6cd5\u5206\u6790\u3001\u8bed\u4e49\u5206\u6790\uff0c\u751f\u6210\u4e2d\u95f4\u4ee3\u7801\u5e76\u4f18\u5316\uff0c\u6700\u7ec8\u8f93\u51fa\u6c47\u7f16\u4ee3\u7801\uff08.s\uff09 \u6c47\u7f16\u9636\u6bb5\uff1a\u5c06\u6c47\u7f16\u4ee3\u7801\u8f6c\u6362\u4e3a\u673a\u5668\u6307\u4ee4\uff0c\u751f\u6210\u4e8c\u8fdb\u5236\u76ee\u6807\u6587\u4ef6\uff08.o\/.obj\uff09 \u94fe\u63a5\u9636\u6bb5\uff1a\u5408\u5e76\u591a\u4e2a\u76ee\u6807\u6587\u4ef6\u548c\u5e93\u6587\u4ef6\uff0c\u89e3\u6790\u7b26\u53f7\u5f15\u7528\uff0c\u751f\u6210\u6700\u7ec8\u53ef\u6267\u884c\u7a0b\u5e8f \u6bcf\u4e2a\u9636\u6bb5\u90fd\u6709\u7279\u5b9a\u7684\u8f93\u5165\u548c\u8f93\u51fa\uff0c\u901a\u8fc7GCC\u7b49\u7f16\u8bd1\u5668\u5de5\u5177\u94fe\u53ef\u4ee5\u9010\u6b65\u89c2\u5bdf\u8fd9\u4e00\u8f6c\u6362\u8fc7\u7a0b\u3002\u7406","og_url":"https:\/\/www.wsisp.com\/helps\/56856.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-08-14T15:54:40+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/56856.html","url":"https:\/\/www.wsisp.com\/helps\/56856.html","name":"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-08-14T15:54:40+00:00","dateModified":"2025-08-14T15:54:40+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/56856.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/56856.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/56856.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"c++\u6e90\u6587\u4ef6\u5230\u53ef\u6267\u884c\u7a0b\u5e8f\u7684\u8be6\u7ec6\u8fc7\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/56856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=56856"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/56856\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=56856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=56856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=56856"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=56856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}