{"id":4572,"date":"2019-08-24T00:49:24","date_gmt":"2019-08-23T16:49:24","guid":{"rendered":"https:\/\/www.linuxcool.com\/?p=4572"},"modified":"2022-05-18T00:17:30","modified_gmt":"2022-05-17T16:17:30","slug":"gcc","status":"publish","type":"post","link":"https:\/\/www.linuxcool.com\/gcc","title":{"rendered":"gcc\u547d\u4ee4 – C\/C++\u8bed\u8a00\u7f16\u8bd1\u5668"},"content":{"rendered":"\n

gcc\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201cGNU Compiler Collection\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8eC\/C++\u8bed\u8a00\u7f16\u8bd1\u5668\u3002gcc\u662f\u5f00\u6e90\u9886\u57df\u4f7f\u7528\u6700\u5e7f\u6cdb\u7684\u7f16\u8bd1\u5de5\u5177\uff0c\u5177\u6709\u529f\u80fd\u5f3a\u5927\u3001\u517c\u5bb9\u6027\u5f3a\uff0c\u6548\u7387\u9ad8\u7b49\u7279\u70b9\u3002<\/p>\n\n\n\n

\u7f16\u8bd1\u5de5\u4f5c\u7684\u56db\u4e2a\u9636\u6bb5\uff1a\u9884\u7f16\u8bd1\uff08Preprocessing)\u3001\u7f16\u8bd1(Compilation)\u3001\u6c47\u7f16 (Assembly)\u3001\u8fde\u63a5(Linking)\u3002<\/p>\n\n\n\n

\u8bed\u6cd5\u683c\u5f0f\uff1a<\/strong>gcc [\u53c2\u6570] \u6e90\u6587\u4ef6<\/p>\n\n\n\n

\u5e38\u7528\u53c2\u6570\uff1a<\/strong><\/p>\n\n\n\n

-o<\/td>\u6307\u5b9a\u751f\u6210\u7684\u8f93\u51fa\u6587\u4ef6<\/td><\/tr>
-E<\/td>\u4ec5\u6267\u884c\u7f16\u8bd1\u9884\u5904\u7406<\/td><\/tr>
-S<\/td>\u5c06C\u4ee3\u7801\u8f6c\u6362\u4e3a\u6c47\u7f16\u4ee3\u7801<\/td><\/tr>
-wall<\/td>\u663e\u793a\u8b66\u544a\u4fe1\u606f<\/td><\/tr>
-c<\/td>\u4ec5\u6267\u884c\u7f16\u8bd1\u64cd\u4f5c\uff0c\u4e0d\u8fdb\u884c\u8fde\u63a5\u64cd\u4f5c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n

\u53c2\u8003\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n

\u7f16\u8bd1\u6307\u5b9a\u7684\u6e90\u7801\u6587\u4ef6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gcc linux.c<\/strong><\/pre>\n\n\n\n

\u7f16\u8bd1\u6307\u5b9a\u7684\u6e90\u7801\u6587\u4ef6\uff0c\u5e76\u751f\u6210\u51fa\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gcc linux.c -o linux<\/strong><\/pre>\n\n\n\n

\u5bf9\u6307\u5b9a\u7684\u6e90\u7801\u6587\u4ef6\u8fdb\u884c\u9884\u5904\u7406\uff1a<\/p>\n\n\n\n

\r[root@linuxcool ~]# gcc -E linux.c -o linux.i<\/strong><\/pre>\n\n\n\n

\u5bf9\u6307\u5b9a\u9884\u5904\u7406\u540e\u7684\u6587\u4ef6\u8fdb\u884c\u6c47\u7f16\u64cd\u4f5c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gcc -S linux.i -o linux.s<\/strong><\/pre>\n\n\n\n

\u5bf9\u6307\u5b9a\u6c47\u7f16\u5904\u7406\u540e\u7684\u6587\u4ef6\u8fdb\u884c\u7f16\u8bd1\u64cd\u4f5c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gcc -c linux.s -o linux.o<\/strong><\/pre>\n\n\n\n

\u5bf9\u6307\u5b9a\u7f16\u8bd1\u5904\u7406\u540e\u7684\u6587\u4ef6\u8fdb\u884c\u8fde\u63a5\u64cd\u4f5c\uff1a<\/p>\n\n\n\n

[root@linuxcool ~]# gcc linux.o -o linux<\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"

gcc\u547d\u4ee4\u6765\u81ea\u4e8e\u82f1\u6587\u8bcd\u7ec4\u201cGNU Compiler Collection\u201d\u7684\u7f29\u5199\uff0c\u5176\u529f\u80fd\u662f\u7528\u4e8eC\/C++\u8bed\u8a00\u7f16 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4572"}],"collection":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/comments?post=4572"}],"version-history":[{"count":14,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4572\/revisions"}],"predecessor-version":[{"id":9816,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/posts\/4572\/revisions\/9816"}],"wp:attachment":[{"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/media?parent=4572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/categories?post=4572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxcool.com\/wp-json\/wp\/v2\/tags?post=4572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}