{"id":18124,"date":"2024-11-18T10:30:04","date_gmt":"2024-11-18T02:30:04","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18124\/"},"modified":"2024-11-18T10:30:04","modified_gmt":"2024-11-18T02:30:04","slug":"linux%e6%80%8e%e4%b9%88%e7%94%a8gcc%e7%bc%96%e8%af%91","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18124\/","title":{"rendered":"linux\u600e\u4e48\u7528gcc\u7f16\u8bd1"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u4e2d\u4f7f\u7528 gcc \u7f16\u8bd1\uff1a\u5b89\u88c5 gcc\uff08sudo apt-get install gcc g++\uff09\uff1b\u521b\u5efa\u6e90\u6587\u4ef6\uff08example.c\uff09\uff1b\u7f16\u8bd1\u6e90\u6587\u4ef6\uff08gcc example.c -o example\uff09\uff1b\u8fd0\u884c\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08.\/example\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060313061924538.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u7528gcc\u7f16\u8bd1\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u7528gcc\u7f16\u8bd1\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Linux \u4e2d\u4f7f\u7528 GCC \u7f16\u8bd1<\/strong><\/p>\n<p>GCC\uff08GNU Compiler Collection\uff09\u662f\u4e00\u6b3e\u5e7f\u6cdb\u7528\u4e8e\u7f16\u8bd1 C \u548c C++ \u7a0b\u5e8f\u7684\u7f16\u8bd1\u5668\u3002\u5728 Linux \u7cfb\u7edf\u4e2d\u4f7f\u7528 GCC \u7f16\u8bd1\u4ee3\u7801\u5341\u5206\u7b80\u5355\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u5b89\u88c5 GCC<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 GCC\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>sudo apt-get install gcc g++<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u521b\u5efa\u6e90\u6587\u4ef6<\/strong><\/p>\n<p>\u7528\u4f60\u559c\u6b22\u7684\u6587\u672c\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2a\u6e90\u6587\u4ef6\uff0c\u4f8b\u5982 example.c\uff1a<\/p>\n<pre>#include &lt;stdio.h&gt;\n\nint main() {\n    printf(\"Hello, world!\n\");\n    return 0;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u7f16\u8bd1\u6e90\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528 gcc \u547d\u4ee4\u7f16\u8bd1\u6e90\u6587\u4ef6\uff1a<\/p>\n<pre>gcc example.c -o example<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>-o \u9009\u9879\u6307\u5b9a\u4e86\u8f93\u51fa\u6587\u4ef6\u540d\u3002<\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u8fd0\u884c\u4e8c\u8fdb\u5236\u6587\u4ef6<\/strong><\/p>\n<p>\u7f16\u8bd1\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff1a<\/p>\n<pre>.\/example<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\u5e94\u4e3a\uff1a<\/p>\n<pre>Hello, world!<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u9009\u9879<\/strong><\/p>\n<p>GCC \u63d0\u4f9b\u4e86\u5404\u79cd\u5176\u4ed6\u9009\u9879\u6765\u63a7\u5236\u7f16\u8bd1\u8fc7\u7a0b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u9009\u9879\uff1a<\/p>\n<ul>\n<li>-Wall\uff1a\u542f\u7528\u6240\u6709\u8b66\u544a\u6d88\u606f\u3002<\/li>\n<li>-Werror\uff1a\u5c06\u8b66\u544a\u89c6\u4e3a\u9519\u8bef\u3002<\/li>\n<li>-O2\uff1a\u4f18\u5316\u4ee3\u7801\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<li>-g\uff1a\u751f\u6210\u8c03\u8bd5\u4fe1\u606f\u3002<\/li>\n<li>-I\/path\/to\/include\uff1a\u6307\u5b9a\u5305\u542b\u5934\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<li>-L\/path\/to\/library\uff1a\u6307\u5b9a\u5b58\u653e\u5e93\u6587\u4ef6\u7684\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p>\u6709\u5173 GCC \u6240\u6709\u53ef\u7528\u9009\u9879\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u8003\u5b98\u65b9\u624b\u518c\u9875\uff1a<\/p>\n<pre>man gcc<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528gcc\u7f16\u8bd1\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u4e2d\u4f7f\u7528 gcc \u7f16\u8bd1\uff1a\u5b89\u88c5 gcc\uff08sudo apt-get install gcc g++\uff09\uff1b\u521b\u5efa\u6e90\u6587\u4ef6\uff08example.c\uff09\uff1b\u7f16\u8bd1\u6e90\u6587\u4ef6\uff08gcc example.c -o example\uff09\uff1b\u8fd0\u884c\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08.\/example\uff09\u3002 \u5982\u4f55\u5728 Linux \u4e2d\u4f7f\u7528 GCC \u7f16\u8bd1 GCC\uff08GNU Compiler Collection\uff09\u662f\u4e00\u6b3e\u5e7f\u6cdb\u7528\u4e8e\u7f16\u8bd1 C \u548c C++ \u7a0b\u5e8f\u7684\u7f16\u8bd1\u5668\u3002\u5728 Linux \u7cfb\u7edf\u4e2d\u4f7f\u7528 GCC \u7f16\u8bd1\u4ee3\u7801\u5341\u5206\u7b80\u5355\u3002 \u6b65\u9aa4 1\uff1a\u5b89\u88c5 GCC \u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5 GCC\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a sudo apt-get install gcc g++ \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u521b\u5efa\u6e90\u6587\u4ef6 \u7528\u4f60\u559c\u6b22\u7684\u6587\u672c\u7f16\u8f91\u5668\u521b\u5efa\u4e00\u4e2a\u6e90\u6587\u4ef6\uff0c\u4f8b\u5982 example.c\uff1a #include &lt;stdio.h&gt; int main() { printf(&#8220;Hello, world! &#8220;); return 0; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18124","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18124","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18124"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18124\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}