{"id":280,"date":"2021-08-23T20:36:41","date_gmt":"2021-08-23T12:36:41","guid":{"rendered":"https:\/\/blogs.gongqilin.cn\/?p=280"},"modified":"2021-08-23T20:36:41","modified_gmt":"2021-08-23T12:36:41","slug":"%e5%85%b3%e4%ba%8ec%e5%85%a8%e5%b1%80%e5%af%b9%e8%b1%a1%e4%b8%8d%e8%b0%83%e7%94%a8%e6%9e%84%e9%80%a0%e5%87%bd%e6%95%b0%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/blogs.gongqilin.cn\/?p=280","title":{"rendered":"\u5173\u4e8eC++\u5168\u5c40\u5bf9\u8c61\u4e0d\u8c03\u7528\u6784\u9020\u51fd\u6570\u7684\u95ee\u9898"},"content":{"rendered":"<h1>\u80cc\u666f<\/h1>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 14pt;\">\u6211\u4eec\u77e5\u9053main\u51fd\u6570\u4e4b\u5916\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u5982\u679c\u5728\u4e0d\u540c\u7684cpp\u6587\u4ef6\uff0c\u5176\u6784\u9020\u51fd\u6570\u7684\u6267\u884c\u987a\u5e8f\u662f\u4e0d\u53ef\u63a7\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6307\u9488\u6307\u98de\u7b49\u5f02\u5e38\uff0c\u56e0\u6b64\uff0c\u6784\u9020\u51fd\u6570\u91cc\u53ea\u505a\u4e00\u4e9b\u7b80\u5355\u7684\u53d8\u91cf\u7684\u521d\u59cb\u5316\u3002\u800c\u5728STM32\u5e73\u53f0\u4f7f\u7528C++\u7f16\u7801\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u53d1\u73b0\u5168\u5c40\u5bf9\u8c61\u548c\u9759\u6001\u5bf9\u8c61\uff0c\u5728\u4f7f\u7528\u4e2d\u51fa\u73b0\u5f02\u5e38\uff0c\u6211\u80fd\u591f\u5728\u7a0b\u5e8f\u4e2d\u8c03\u7528\u8fd9\u4e2a\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002\u4f46\u662f\u6267\u884c\u540e\u4e0e\u9884\u671f\u7ed3\u679c\u4e0d\u7b26\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h1>\u5206\u6790<\/h1>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 14pt;\">\u901a\u8fc7\u4e32\u53e3\u6253\u5370\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u53d1\u73b0\u8fd9\u4e2a\u5bf9\u8c61\u7684\u5c5e\u6027\u6ca1\u6709\u5728\u6784\u9020\u65f6\u95f4\u8bbe\u7f6e\u6210\u529f\uff0c\u7531\u6b64\u6211\u6000\u7591\u8fd9\u4e2a\u5bf9\u8c61\u5728\u751f\u6210\u65f6\u6839\u672c\u6ca1\u6709\u8c03\u7528\uff0c\u4e3a\u4e86\u9a8c\u8bc1\u8fd9\u4e2a\u60f3\u6cd5\uff0c\u5b9a\u4e49\u4e86\u5168\u5c40\u53d8\u91cf\uff0c\u5728\u6784\u9020\u51fd\u6570\u4e2d\u53bb\u6539\u53d8\u5b83\uff0c\u5206\u522b\u67e5\u770b\u751f\u6210\u5168\u5c40\u5bf9\u8c61\u548c\u751f\u6210\u5c40\u90e8\u5bf9\u8c61\u65f6\uff0c\u8fd9\u4e2a\u503c\u7684\u53d8\u5316\u60c5\u51b5\u3002\u53ef\u4ee5\u786e\u5b9a\u5168\u5c40\u7684\u5bf9\u8c61\u5e76\u6ca1\u6709\u8c03\u7528\u6784\u9020\u51fd\u6570\u3002\u901a\u8fc7\u68c0\u7d22\u89e3\u51b3\u65b9\u6848\u6211\u53d1\u73b0\u4e00\u4e2a\u4ecb\u7ecd<a href=\"https:\/\/www.pianshen.com\/article\/7309860645\/\">Linux\u7684C++\u7a0b\u5e8f\u5168\u5c40\u5bf9\u8c61\u4e0d\u8c03\u7528\u6784\u9020\u51fd\u6570\u7684\u95ee\u9898<\/a>\u3002\u8be5\u6587\u7ae0\u63d0\u51fa\u5bfc\u81f4\u5168\u5c40\u5bf9\u8c61\u4e0d\u8c03\u7528\u6784\u9020\u51fd\u6570\u7684\u4e3b\u8981\u539f\u56e0\u662f\u7f16\u8bd1\u5668\u7684\u95ee\u9898\u3002\uff08\u4e3b\u8981\u662f\u5176\u4e2d\u7684\u94fe\u63a5\u5668\u90e8\u5206\uff09\u3002\u540c\u6837\u6211\u60f3\u5230\u4e86STM32\u73b0\u5728\u4e5f\u662f\u5148\u7528g++\u751f\u6210\u4e2d\u95f4\u6587\u4ef6\uff0c\u518d\u7528ld\u94fe\u63a5\u751f\u6210\u6700\u7ec8\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u67e5\u770b\u4f7f\u7528stm32cubemx\u751f\u6210\u7684ld\u94fe\u63a5\u6587\u4ef6\uff0c\u4e4b\u524d\u4e86\u89e3\u8fc7\u4e00\u70b9ld\u811a\u672c\u77e5\u9053\u4e00\u4e9b\u6bb5\u7684\u542b\u4e49\uff0c\u67e5\u627e\u8d44\u6599\u89e3\u8bfb\u5176\u4e2d\u4e00\u4e9b\u4e0d\u8ba4\u8bc6\u7684\u6bb5\uff0c\u53d1\u73b0\u5b58\u5728.init_array\u548c.preinit_array\u6bb5\u3002<\/span><\/p>\n<pre class=\"prettyprint linenums\"> .preinit_array     :\r\n  {\r\n    PROVIDE_HIDDEN (__preinit_array_start = .);\r\n    KEEP (*(.preinit_array*))\r\n    PROVIDE_HIDDEN (__preinit_array_end = .);\r\n  } &gt;FLASH\r\n  .init_array :\r\n  {\r\n    PROVIDE_HIDDEN (__init_array_start = .);\r\n    KEEP (*(SORT(.init_array.*)))\r\n    KEEP (*(.init_array*))\r\n    PROVIDE_HIDDEN (__init_array_end = .);\r\n  } &gt;FLASH\r\n<\/pre>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 14pt;\">\u8be5\u6bb5\u7528\u4e8e\u4fdd\u5b58\u7a0b\u5e8f\u6216\u5171\u4eab\u5bf9\u8c61\u52a0\u8f7d\u65f6\u7684\u521d\u59cb\u5316\u51fd\u6570\u6307\u9488\uff0c\u8fd9\u4e0d\u5c31\u662f\u5168\u5c40\u5bf9\u8c61\u7684\u6784\u9020\u51fd\u6570\u561b\uff1f<\/span><\/p>\n<pre class=\"prettyprint linenums\">.preinit_array  0x08044fbc        0x0\r\n                0x08044fbc                PROVIDE (__preinit_array_start, .)\r\n *(.preinit_array*)\r\n                0x08044fbc                PROVIDE (__preinit_array_end, .)\r\n\r\n.init_array     0x08044fbc       0x1c\r\n                0x08044fbc                PROVIDE (__init_array_start, .)\r\n *(SORT(.init_array.*))\r\n *(.init_array*)\r\n .init_array    0x08044fbc        0x4 c:\/arm\/bin\/..\/lib\/gcc\/arm-none-eabi\/4.5.1\/thumb2\/crtbegin.o\r\n .init_array    0x08044fc0        0x4 OutPut\/bsp.o\r\n .init_array    0x08044fc4        0x4 OutPut\/CSoftPwm.o\r\n .init_array    0x08044fc8        0x4 OutPut\/CSysTime.o\r\n .init_array    0x08044fcc        0x4 OutPut\/CMainApp.o\r\n .init_array    0x08044fd0        0x4 OutPut\/CParser.o\r\n .init_array    0x08044fd4        0x4 c:\/arm\/bin\/..\/lib\/gcc\/arm-none-eabi\/4.5.1\/..\/..\/..\/..\/arm-none-eabi\/lib\/thumb2\\libstdc++.a(eh_alloc.o)\r\n                0x08044fd8                PROVIDE (__init_array_end, .)\r\n<\/pre>\n<p style=\"padding-left: 40px;\"><span style=\"font-size: 14pt;\">\u518d\u6b21\u67e5\u770b\u751f\u6210\u7684map\u6587\u4ef6\u53d1\u73b0\u8be5\u6bb5\u4e0b\u90fd\u662f\u5305\u542b\u4e8e\u5168\u5c40\u5bf9\u8c61\u6216\u8005\u9759\u6001\u5bf9\u8c61\u7684\u6587\u4ef6\uff0c\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u77e5\u9053\u8fd9\u4e9b\u5bf9\u8c61\u7684\u521d\u59cb\u5316\u6307\u9488\u90fd\u5b58\u653e\u5728\u8be5\u6bb5\u4e0b\uff0c\u95ee\u9898\u5c31\u662f\u5982\u4f55\u8bbf\u95ee\u8be5\u5730\u5740\u4e0b\u7684\u51fd\u6570\u6307\u9488\u4e86\u3002\u67e5\u627e\u8d44\u6599\u53d1\u73b0libc\u5e93\u4e0b\u7684<a href=\"https:\/\/sourceware.org\/git\/gitweb.cgi?p=newlib-cygwin.git;a=blob_plain;f=newlib\/libc\/misc\/init.c;hb=HEAD\">_libc_init_array()<\/a> \u6539\u51fd\u6570\u5c31\u662f\u5bf9preinit_array\u6bb5\u548cinit_array\u6bb5\u7684<\/span><span style=\"font-size: 14pt;\">\u521d\u59cb\u5316\u51fd\u6570\u6307\u9488\u8fdb\u884c\u8c03\u7528\u6267\u884c\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h1>\u7ed3\u8bba<\/h1>\n<p style=\"padding-left: 40px;\">\u00a0<span style=\"font-size: 14pt;\">\u7efc\u4e0a\uff0c\u89e3\u51b3C++\u5168\u5c40\u5bf9\u8c61\u4e0d\u8c03\u7528\u6784\u9020\u51fd\u6570\u7684\u95ee\u9898\uff0c\u53ea\u9700\u8981\u5728stm32\u7684\u542f\u52a8 \u6587\u4ef6\u4e2d\uff0c\u5728\u8c03\u7528main\uff08\uff09\u51fd\u6570\u524d\u8c03\u7528_libc_init_array(\uff09\u5373\u53ef<\/span><\/p>\n<pre class=\"prettyprint linenums\">\/* Call the clock system intitialization function.*\/\r\n  bl  SystemInit   \r\n\/* Call static constructors *\/\r\n    bl __libc_init_array\r\n\/* Call the application&#039;s entry point.*\/\r\n  bl  main\r\n  bx  lr   \r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u80cc\u666f \u6211\u4eec\u77e5\u9053main\u51fd\u6570\u4e4b\u5916\u7684\u5168\u5c40\u53d8\u91cf\uff0c\u5982\u679c\u5728\u4e0d\u540c\u7684cpp\u6587\u4ef6\uff0c\u5176\u6784\u9020\u51fd\u6570\u7684\u6267\u884c\u987a\u5e8f\u662f\u4e0d\u53ef\u63a7\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u6307\u9488 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-12"],"_links":{"self":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/280","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=280"}],"version-history":[{"count":3,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions"}],"predecessor-version":[{"id":283,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=\/wp\/v2\/posts\/280\/revisions\/283"}],"wp:attachment":[{"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.gongqilin.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}