{"id":257,"date":"2021-04-23T14:25:39","date_gmt":"2021-04-23T06:25:39","guid":{"rendered":"https:\/\/blogs.gongqilin.cn\/?p=257"},"modified":"2021-04-23T14:58:43","modified_gmt":"2021-04-23T06:58:43","slug":"%e9%a2%84%e5%a4%84%e7%90%86-%e6%96%87%e4%bb%b6%e5%8c%85%e5%90%ab%ef%bc%88include%ef%bc%89%e5%8f%af%e8%83%bd%e5%bc%95%e5%8f%91%e7%9a%84%e7%bc%96%e8%af%91%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/blogs.gongqilin.cn\/?p=257","title":{"rendered":"\u9884\u5904\u7406&#8211;\u6587\u4ef6\u5305\u542b\uff08#include\uff09\u53ef\u80fd\u5f15\u53d1\u7684\u7f16\u8bd1\u9519\u8bef"},"content":{"rendered":"<p>#include\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6587\u4ef6\u7684\u5168\u90e8\u5185\u5bb9\u62f7\u8d1d\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002\u90a3\u5982\u679c\u8fd9\u4e2a\u5305\u542b\u7684\u6587\u4ef6\u51fa\u9519\uff0c\u53ef\u80fd\u62a5\u9519\u7684\u5c31\u4e0d\u5728\u8fd9\u4e2a\u6587\u4ef6\u4e2d\u3002<\/p>\n<p>\u8fd9\u91cc\u6709\u4e00\u4e2aCMainApp.cpp\u6587\u4ef6\uff0c\u4ed6\u5305\u542b\u4e86\u4e09\u4e2a\u5934\u6587\u4ef6\uff0c\u5206\u522b\u662fCMainApp.h,aaa.h\uff0cCMcuFlash.h\u3002<\/p>\n<pre class=\"prettyprint linenums\">#include &quot;CMainApp.h&quot;\r\n#include &quot;aaa.h&quot;\r\n#include &quot;CMcuFlash.h&quot;\r\n<\/pre>\n<p>\u5728aaa.h\u6587\u4ef6\u91cc\u9762\u4e5f\u5f88\u7b80\u5355\uff0c\u5c31\u662f\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b<\/p>\n<pre class=\"prettyprint linenums\">class AAA\r\n{\r\n}\r\n<\/pre>\n<p>\u90a3\u4e48\u8fd9\u4e2a\u65f6\u5019\u7f16\u8bd1\u4e00\u4e0b\uff0cgcc\u62a5\u9519<\/p>\n<pre class=\"prettyprint linenums\">In file included from src\/App\/CMainApp.cpp:13:0:\r\nsrc\/driver\/OnChip\/CMcuFlash.h:35:9: error: &#039;#pragma&#039; is not allowed here\r\nsrc\/driver\/OnChip\/CMcuFlash.h:36:16: error: expected declaration before end of line\r\n<\/pre>\n<p>\u8fd9\u91cc\u6211\u4eec\u770b\u5230\uff0c\u5728CMainApp.cpp\u5904\u7406\u7b2c13\u884c\u5305\u542b\u6587\u4ef6\u7684\u65f6\u5019\u51fa\u9519\uff0c\u9519\u8bef\u7684\u662fCMcuFlash.h\u5728\u7b2c35\u884c#pragma\u4e0d\u5141\u8bb8\u653e\u5728\u8fd9\u91cc\u3002<br \/>\n\u8fd9\u91cc\u6253\u5f00\u67e5\u770bCMcuFlash.h\u6587\u4ef6\uff0c\u53d1\u73b0\u6587\u4ef6\u5934\u5b9a\u4e49\u5982\u4e0b\uff0c\u5e76\u6ca1\u6709\u53d1\u73b0#pragma<\/p>\n<pre class=\"prettyprint linenums\">#ifndef __CMCUFLASH_H\r\n#define __CMCUFLASH_H\r\n\r\n#include &quot;lib.h&quot; \r\n#include &quot;sys_config.h&quot; \r\n<\/pre>\n<p>\u7ee7\u7eed\u6253\u5f00CMcuFlash.h\u6240\u5305\u542b\u7684lib.h\u6587\u4ef6\uff0c\u8fd9\u4e2a\u65f6\u5019\u5c31\u53d1\u73b0\u9876\u90e8\u7684\u9884\u5904\u7406\u6307\u4ee4<\/p>\n<pre class=\"prettyprint linenums\">#pragma once\r\n<\/pre>\n<p>\u90a3\u4e48\u4e3a\u4ec0\u4e48gcc\u4f1a\u62a5\u9519\u5728CMcuFlash.h\u5462\uff1f\u4e0d\u77e5\u9053\u8bfb\u8005\u6709\u6ca1\u6709\u6ce8\u610f\u5230\uff0c\u5b9a\u4e49class AAA\u7684\u65f6\u5019\uff0c\u6700\u540e\u6ca1\u6709\u5206\u53f7\u3002\u5e94\u8be5\u4fee\u6539\u5982\u4e0b<\/p>\n<pre class=\"prettyprint linenums\">class AAA\r\n{\r\n};\r\n<\/pre>\n<p>\u5728\u539f\u6765\u7684\u6ca1\u6709\u5206\u53f7\u7684\u65f6\u5019\uff0cCMainApp.cpp\u4f7f\u7528#include\u628aaaa.h\uff0cCMcuFlash.h\u5168\u90e8\u590d\u5236\u5230CMainApp.cpp\u4e2d\uff0cCMcuFlash.h\u8fd8\u4f1a\u628alib.h\u590d\u5236\u8fdb\u53bb\uff0c\u7f16\u8bd1\u9884\u5904\u7406\u4e4b\u540eCMainApp.cpp\u6587\u4ef6\u5982\u4e0b<\/p>\n<pre class=\"prettyprint linenums\">class AAA\r\n{\r\n}\r\n#pragma once\r\n<\/pre>\n<p>\u663e\u7136\u8fd9\u662f\u4e0d\u5bf9\u7684\uff0cgcc\u8fd9\u4e00\u6bb5\u7684\u9519\u8bef\u6765\u81eaCMcuFlash.h\u3002<br \/>\n\u6240\u4ee5\u5f53\u7f16\u8bd1\u65f6\uff0c\u7279\u522b\u662f\u65b0\u589e\u4e86\u4e00\u4e2a\u6587\u4ef6\u8fdb\u884c\u7f16\u8bd1\uff0c\u53d1\u73b0\u4e4b\u524d\u6ca1\u6709\u95ee\u9898\u7684\u6587\u4ef6\u5374\u51fa\u73b0\u4e86\u4e00\u4e9b\u83ab\u540d\u7684\u95ee\u9898\uff0c\u6bd4\u5982CMcuFlash.h\u6ca1\u6709\u7f16\u8bd1\u662f\u6ca1\u95ee\u9898\u7684\uff0c\u4e14\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\u6ca1\u6709#pragma\uff0c\u90a3\u4e48\u53ef\u4ee5\u5c31\u662f\u4e4b\u524d\u5305\u542b\u7684\u6587\u4ef6\u51fa\u73b0\u95ee\u9898\u4e86\u3002\u7279\u522b\u662f\u51fa\u73b0<\/p>\n<ul>\n<li>\u6700\u540e\u7684\u62ec\u53f7\u672a\u8865\u9f50\u3002<\/li>\n<li>\u7ed3\u5c3e\u7684\uff1b\u672a\u8865\u9f50\u3002<\/li>\n<li>\u4f7f\u7528\u4e86#if\uff0c#ifdef,#ifndef\u7b49\u6761\u4ef6\u7f16\u8bd1\u672a\u6dfb\u52a0#endif<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u5305\u542b\u7684\u6587\u4ef6\u6b63\u5e38\u7684\u60c5\u51b5\u4e0b\u5e94\u5f53\u65e9\u4e8e\uff0c\u6761\u4ef6\u7f16\u8bd1\u7684\u8bed\u53e5\uff0c\u4f8b\u5982\u5728aaa.h\u5b9a\u4e49\u4e00\u4e2a#define TEST\uff0c<\/p>\n<pre class=\"prettyprint linenums\" >\r\n#ifndef TEST\r\n    #error &quot;Not define TEST&quot;\r\n#else\r\n    #error &quot;define TEST&quot;\r\n#endif    \r\n\r\n#include &quot;aaa.h&quot;\r\n\r\n#ifndef TEST\r\n    #error &quot;Not define TEST&quot;\r\n#else\r\n    #error &quot;define TEST&quot;\r\n#endif \r\n<\/pre>\n<p>\u8fd9\u4e2a\u65f6\u5019gcc\u6253\u5370\u4fe1\u606f\u53ef\u4ee5\u770b\u5230<\/p>\n<pre class=\"prettyprint linenums\" >\r\nsrc\/App\/CMainApp.cpp:23:6: error: #error &quot;Not define TEST&quot;\r\nsrc\/App\/CMainApp.cpp:33:6: error: #error &quot;define TEST&quot;\r\n<\/pre>\n<p>\u8fd9\u5c31\u662f\u56e0\u4e3a\u524d\u9762\u8fdb\u884c\u9884\u7f16\u8bd1\u8fd9\u4e2a\u65f6\u5019\u8fd8\u672a\u5305\u542baaa.h\uff08\u590d\u5236\u5185\u5bb9\uff09\u8fdb\u6765\uff0c\u5c31\u6ca1\u6709TEST\u8fd9\u4e2a\u5b8f\uff0c\u540e\u8fb9\u5305\u542baaa.h\u540e\u8ba4\u4e3a\u8be5\u6587\u4ef6\u5b9a\u4e49\u4e86\u8fd9\u4e2a\u5b8f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include\uff0c\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u6587\u4ef6\u7684\u5168\u90e8\u5185\u5bb9\u62f7\u8d1d\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u3002\u90a3\u5982\u679c\u8fd9\u4e2a\u5305\u542b\u7684\u6587\u4ef6\u51fa\u9519\uff0c\u53ef\u80fd\u62a5\u9519\u7684\u5c31\u4e0d\u5728\u8fd9\u4e2a\u6587 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,12],"tags":[15],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-c","category-12","tag-include"],"_links":{"self":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257"}],"version-history":[{"count":5,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions"}],"predecessor-version":[{"id":262,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions\/262"}],"wp:attachment":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}