{"id":315,"date":"2022-02-07T22:45:44","date_gmt":"2022-02-07T14:45:44","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=315"},"modified":"2022-03-19T20:57:22","modified_gmt":"2022-03-19T12:57:22","slug":"ninja-%e5%8f%88%e4%b8%80%e4%b8%aac%e6%9e%84%e5%bb%ba%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=315","title":{"rendered":"\u7528 Ninja and GN \u6765\u52a0\u901f C++\u6784\u5efa"},"content":{"rendered":"<h1>Ninja<\/h1>\n<p>Ninja \u539f\u610f\u662f\u5fcd\u8005\u7684\u610f\u601d\uff0c\u5b83\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u901f\u5ea6\u7684\u5c0f\u578b\u6784\u5efa\u5de5\u5177\u3002\u5b83\u662f\u4e00\u4e2a\u6784\u5efa\u7cfb\u7edf\u3002 \u5b83\u5c06\u6587\u4ef6\u7684\u76f8\u4e92\u4f9d\u8d56\u5173\u7cfb\uff08\u901a\u5e38\u662f\u6e90\u4ee3\u7801\u548c\u8f93\u51fa\u53ef\u6267\u884c\u6587\u4ef6\uff09\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u5feb\u901f\u7f16\u6392\u6784\u5efa\u5b83\u4eec\u3002<\/p>\n<p>\u8fd0\u884cNinja\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u67e5\u627e\u540d\u4e3a build.ninja \u7684\u6587\u4ef6\u5e76\u6784\u5efa\u6240\u6709\u8fc7\u65f6\u7684\u76ee\u6807\u3002 \u60a8\u53ef\u4ee5\u6307\u5b9a\u8981\u6784\u5efa\u7684\u76ee\u6807\uff08\u6587\u4ef6\uff09\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bed\u6cd5 target^ \u7528\u4e8e\u5c06\u76ee\u6807\u6307\u5b9a\u4e3a\u67d0\u4e2a\u89c4\u5219\u7684\u7b2c\u4e00\u4e2a\u8f93\u51fa\uff0c\u5176\u4e2d\u5305\u542b\u60a8\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u7684\u6e90\uff08\u5982\u679c\u5b58\u5728\uff09\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u60a8\u5c06\u76ee\u6807\u6307\u5b9a\u4e3a foo.c^\uff0c\u90a3\u4e48 foo.o \u5c06\u88ab\u6784\u5efa\uff08\u5047\u8bbe\u60a8\u7684\u6784\u5efa\u6587\u4ef6\u4e2d\u6709\u8fd9\u4e9b\u76ee\u6807\uff09\u3002<\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u624b\u5199 ninja \u6587\u4ef6\uff0c\u901a\u8fc7 gn \u6216 cmake \u6765\u63cf\u8ff0\u9879\u76ee\u7ed3\u6784\u548c\u4f9d\u8d56\u5173\u7cfb\uff0c\u518d\u901a\u8fc7\u5b83\u4eec\u6765\u751f\u6210 build.ninja \u6587\u4ef6<\/p>\n<p>\u8be6\u89c1Ninja \u624b\u518c - <a href=\"https:\/\/ninja-build.org\/manual.html\">https:\/\/ninja-build.org\/manual.html<\/a>\uff0c<\/p>\n<h1>Example<\/h1>\n<h2>byteorder.c<\/h2>\n<pre><code class=\"language-cpp\">#include &lt;stdio.h&gt;\n\nint main(int argc, char **argv)\n{\n    union {\n        short s;\n        char c[sizeof(short)];\n    }un;\n    un.s = 0x0102;\n\n    if (sizeof(short) == 2) {\n        if (un.c[0] == 1 &amp;&amp; un.c[1] == 2)\n            printf(&quot;big-endian\\n&quot;);\n        else if (un.c[0] == 2 &amp;&amp; un.c[1] == 1)\n            printf(&quot;little-endian\\n&quot;);\n        else\n            printf(&quot;unknown\\n&quot;);\n   } else{\n        printf(&quot;sizeof(short) = %ld\\n&quot;, sizeof(short));\n   }\n\n   return 0;\n}\n<\/code><\/pre>\n<h2>build.ninja<\/h2>\n<pre><code>cflags = -Wall\n\nrule cc\n  command = gcc $cflags -c $in -o $out\n\nbuild byteorder.o: cc byteorder.c<\/code><\/pre>\n<p>\u53ef\u4ee5\u901a\u8fc7 <code>ninja -C build -j 20 <\/code> \u6765\u6784\u5efa<\/p>\n<h1>gn<\/h1>\n<p>\u987e\u540d\u601d\u4e49\uff0cGN is \u201cGenerate Ninja\u201d \u4e00\u4e2a\u7528\u6765\u751f\u6210 Ninja \u7684\u5de5\u5177<\/p>\n<p>\u7528\u4e8e\u4e3a Google Chrome \u548c\u76f8\u5173\u9879\u76ee\uff08v8\u3001node.js\uff09\u4ee5\u53ca Google Fuchsia \u751f\u6210\u6784\u5efa\u6587\u4ef6\u7684\u5143\u6784\u5efa\u7cfb\u7edf\u3002 gn \u53ef\u4ee5\u4e3a Chrome \u652f\u6301\u7684\u6240\u6709\u5e73\u53f0\u751f\u6210 Ninja \u6587\u4ef6\u3002<\/p>\n<p>GN \u6709\u81ea\u5df1\u5b9a\u4e49\u7684\u4e00 \u5957\u6bd4\u8f83\u7b80\u5355\u7684\u63cf\u8ff0\u6027\u8bed\u8a00\uff0c\u8be6\u89c1 <a href=\"https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/language.md\">https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/language.md<\/a><\/p>\n<p>GN \u4e2d\u6709\u4e09\u4e2a\u91cd\u8981\u7684\u6587\u4ef6<\/p>\n<ol>\n<li><code>.gn<\/code><\/li>\n<\/ol>\n<p>\u5b83\u5b9a\u4e49\u4e86 GN \u6784\u5efa\u6811\u7684\u6839\u8282\u70b9<\/p>\n<p>\u8be6\u89c1\u547d\u4ee4 \u201cgn help dotfile\u201d<\/p>\n<ol start=\"2\">\n<li><code>\/\/build\/config\/BUILDCONFIG.gn<\/code><\/li>\n<\/ol>\n<p>Exact location defined by \u201c.gn\u201d file<br \/>\nSets up global variables and default settings<\/p>\n<ol start=\"3\">\n<li><code>BUILD.gn<\/code><br \/>\n\u63cf\u8ff0\u4e86\u6784\u5efa\u76ee\u6807\uff0c\u6e90\u7801\u6587\u4ef6\uff0c\u53ca\u5176\u4f9d\u8d56\u5173\u7cfb\u7b49<\/li>\n<\/ol>\n<h2>gn args<\/h2>\n<p>\u8fd9\u4e2a\u5de5\u5177\u6709\u4e24\u4e2a\u4f5c\u7528\uff0c\u4e00\u662f\u751f\u6210.ninja\u7f16\u8bd1\u914d\u7f6e\u6587\u4ef6\uff0c\u4e8c\u662f\u67e5\u770b\u5f53\u524d\u7f16\u8bd1\u7684\u6240\u6709\u6807\u8bb0\u9879\u3002<\/p>\n<h3>\u751f\u6210.ninja<\/h3>\n<p>\u8fd9\u4e2a\u5de5\u5177\u7ed9\u7528\u6237\u63d0\u4f9b\u4e00\u4e2a\u63a5\u53e3\uff0c\u6765\u5bf9\u6784\u5efa\u8fdb\u884c\u6574\u4f53\u7684\u914d\u7f6e\u3002\u5982\u5728Chromium Android\u7f16\u8bd1\u6307\u5357\u4e2d\uff0c\u4e3aAndroid\u7248chromium\u505a\u7f16\u8bd1\u914d\u7f6e\u65f6\uff0c\u6240\u6267\u884c\u7684\u547d\u4ee4\uff1a<\/p>\n<pre><code>gn args out\/Default<\/code><\/pre>\n<p>\u53c2\u6570\u662foutput\u76ee\u5f55\u8def\u5f84\u3002\u8fd9\u4e2a\u547d\u4ee4\u542f\u52a8\u7cfb\u7edf\u9ed8\u8ba4\u7684\u7f16\u8f91\u5668\uff0c\u521b\u5efaout\/Default\/args.gn\u6587\u4ef6\uff0c\u6211\u4eec\u5728\u7f16\u8f91\u5668\u4e2d\u52a0\u5165\u6211\u4eec\u81ea\u5df1\u7279\u5b9a\u7684\u914d\u7f6e\u9879\uff0c\u5982\uff1a<\/p>\n<pre><code>target_os = &quot;android&quot;\ntarget_cpu = &quot;arm&quot;  # (default)\nis_debug = true  # (default)\n# Other args you may want to set:\nis_component_build = true\nis_clang = true\nsymbol_level = 1  # Faster build with fewer symbols. -g1 rather than -g2\nenable_incremental_javac = true  # Much faster; experimental<\/code><\/pre>\n<p>gn\u6839\u636e\u521b\u5efa\u5f97\u8fd9\u4e2aout\/Default\/args.gn\u6587\u4ef6\u7684\u5185\u5bb9\u6765\u4ea7\u751fninja\u6587\u4ef6\u3002<\/p>\n<h3>\u67e5\u770b\u5f53\u524d\u7f16\u8bd1\u7684\u6240\u6709\u6807\u8bb0\u9879<\/h3>\n<p>\u8fd9\u4e2a\u5de5\u5177\u8fd8\u53ef\u4ee5\u67e5\u770b\u5f53\u524d\u7f16\u8bd1\u7684\u6240\u6709\u6807\u8bb0\u914d\u7f6e\u9879\u3002chromium\u4e2d\u7528\u5230\u4e86\u8bb8\u8bb8\u591a\u591a\u7684\u6807\u8bb0\u9879\uff0c\u5bf9\u4e8e\u8fd9\u4e9b\u6807\u8bb0\u9879\u4e2d\u7684\u8bb8\u591a\u9879\uff0c\u5373\u4f7f\u7528\u6237\u4e0d\u8fdb\u884c\u914d\u7f6e\uff0cchromium\u7684\u7f16\u8bd1\u7cfb\u7edf\u4e5f\u4f1a\u63d0\u4f9b\u9ed8\u8ba4\u7684\u914d\u7f6e\u3002\u4e86\u89e3\u5230\u5f53\u524d\u7f16\u8bd1\u7684\u6240\u6709\u6807\u8bb0\u914d\u7f6e\u9879\uff0c\u5bf9\u4e8e\u6211\u4eec\u4e86\u89e3\u5b9e\u9645\u7f16\u8bd1\u65f6\u6240\u7528\u7684\u7f16\u8bd1\u53c2\u6570\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<p>\u5bf9\u4e8e\u4e0a\u9762\u8f93\u5165\u7684\u53c2\u6570\uff0c\u4ea7\u751f\u7684\u6574\u4e2a\u7f16\u8bd1\u914d\u7f6e\u73af\u5883\u4e2d\uff0c\u6240\u6709\u7684\u6807\u8bb0\u914d\u7f6e\u9879\u5982\u4e0b\uff1a<\/p>\n<pre><code>$gn args --list out\/Default\/<\/code><\/pre>\n<h2>gn gen<\/h2>\n<p>usage:  gn gen [<ide options>] <out_dir><br \/>\n\u8fd9\u4e2a\u5de5\u5177\u6839\u636e\u5f53\u524d\u7684\u4ee3\u7801\u6811\u53ca\u914d\u7f6e\uff0c\u4ea7\u751fninja\u6587\u4ef6\uff0c\u5e76\u628a\u5b83\u4eec\u653e\u5728\u7ed9\u5b9a\u5f97\u76ee\u5f55\u4e0b\u3002\u8f93\u51fa\u76ee\u5f55\u53ef\u4ee5\u662f\u6e90\u7801\u5e93\u7684\u7edd\u5bf9\u5730\u5740\uff0c\u6bd4\u5982\/\/out\/foo\uff0c\u4e5f\u53ef\u4ee5\u662f\u76f8\u5bf9\u4e8e\u5f53\u524d\u76ee\u5f55\u7684\u5730\u5740\uff0c\u5982\uff1aout\/foo\u3002 \u4e0a\u9762\u7684gn args <out_dir>\u7b49\u4ef7\u4e8e\uff0c\u5728\u542f\u52a8\u7f16\u8f91\u5668\u7f16\u8f91\u53c2\u6570\uff0c\u5728\u7f16\u8f91\u5668\u7f16\u8f91\u4e86\u53c2\u6570\u9000\u51fa\u4e4b\u540e\uff0c\u6267\u884cgn gen <out_dir>\u3002<\/p>\n<h2>gn clean<\/h2>\n<p>usage:  gn clean <out_dir><\/p>\n<p>\u8fd9\u4e2a\u547d\u4ee4\u7528\u4e8e\u5bf9\u5386\u53f2\u7f16\u8bd1\u8fdb\u884c\u6e05\u7406\u3002\u5b83\u4f1a\u5220\u9664\u8f93\u51fa\u76ee\u5f55\u4e0b\u9664\u4e86args.gn\u5916\u5f97\u5185\u5bb9\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u91cd\u65b0\u4ea7\u751f\u6784\u5efa\u914d\u7f6e\u7684Ninja\u6784\u5efa\u73af\u5883\u3002<\/p>\n<h2>gn desc<\/h2>\n<p>usage:  gn desc <out_dir> <label or pattern> [<what to show>] [--blame] [--format=json]<\/p>\n<p>\u663e\u793a\u5173\u4e8e\u4e00\u4e2a\u7ed9\u5b9atarget\u6216config\u7684\u4fe1\u606f\u3002\u6784\u5efa\u53c2\u6570\u53d6\u81ea\u7ed9\u51fa\u7684<out_dir>\u3002<label or pattern>\u53ef\u4ee5\u662f\u4e00\u4e2atarget\u6807\u7b7e\uff0c\u4e00\u4e2aconfig\u6807\u7b7e\uff0c\u6216\u4e00\u4e2a\u6807\u7b7e\u6a21\u5f0f(\u53c2\u8003&quot;gn help label_pattern&quot;)\u3002\u6807\u7b7e\u6a21\u5f0f\u53ea\u5339\u914dtargets\u3002<\/p>\n<p>\u5982\u6211\u4eec\u8981\u67e5\u770b webrtc \u4e2d gcc \u6a21\u5757\u76f8\u5173\u5f97\u6240\u6709\u4fe1\u606f\uff1a<\/p>\n<pre><code>$ gn desc out\/Default \/\/modules\/congestion_controller\/goog_cc --tree<\/code><\/pre>\n<h2>gn ls<\/h2>\n<p>usage: gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...] [--type=...] [--testonly=...]<br \/>\n\u8fd9\u4e2a\u547d\u4ee4\u5c55\u793a\u7ed9\u5b9a\u8f93\u51fa\u76ee\u5f55\u4e0b\uff0c\u6ee1\u8db3\u67d0\u4e2a\u6a21\u5f0f\u7684\u6240\u6709\u7684targets\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53ea\u663e\u793a\u9ed8\u8ba4\u5de5\u5177\u94fe\u7684target\u4f1a\u88ab\u5339\u914d\uff0c\u9664\u975e\u660e\u786e\u5730\u63d0\u4f9b\u4e86\u5de5\u5177\u94fe\u53c2\u6570\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a\u6807\u7b7e\u53c2\u6570\uff0c\u5219\u663e\u793a\u6240\u6709\u7684targets\u3002\u6a21\u5f0f\u4e0d\u662f\u5e38\u89c4\u7684\u6b63\u5219\u8868\u8fbe\u5f0f(\u53ef\u4ee5\u53c2\u8003&quot;gn help label_pattern&quot;)\u3002<\/p>\n<pre><code>$ gn ls out\/Default &quot;\/\/modules\/congestion_controller\/*&quot;\n\/\/modules\/congestion_controller:congestion_controller\n\/\/modules\/congestion_controller:congestion_controller_unittests\n\/\/modules\/congestion_controller\/goog_cc:alr_detector\n\/\/modules\/congestion_controller\/goog_cc:delay_based_bwe\n\/\/modules\/congestion_controller\/goog_cc:estimators\n\/\/modules\/congestion_controller\/goog_cc:goog_cc\n\/\/modules\/congestion_controller\/goog_cc:goog_cc_unittests\n\/\/modules\/congestion_controller\/goog_cc:link_capacity_estimator\n\/\/modules\/congestion_controller\/goog_cc:loss_based_bwe_v1\n\/\/modules\/congestion_controller\/goog_cc:loss_based_bwe_v2\n\/\/modules\/congestion_controller\/goog_cc:probe_controller\n\/\/modules\/congestion_controller\/goog_cc:pushback_controller\n\/\/modules\/congestion_controller\/goog_cc:send_side_bwe\n\/\/modules\/congestion_controller\/goog_cc:test_goog_cc_printer\n\/\/modules\/congestion_controller\/pcc:bitrate_controller\n\/\/modules\/congestion_controller\/pcc:monitor_interval\n\/\/modules\/congestion_controller\/pcc:pcc\n\/\/modules\/congestion_controller\/pcc:pcc_controller\n\/\/modules\/congestion_controller\/pcc:pcc_unittests\n\/\/modules\/congestion_controller\/pcc:rtt_tracker\n\/\/modules\/congestion_controller\/pcc:utility_function\n\/\/modules\/congestion_controller\/rtp:congestion_controller_unittests\n\/\/modules\/congestion_controller\/rtp:control_handler\n\/\/modules\/congestion_controller\/rtp:transport_feedback<\/code><\/pre>\n<h2>gn check<\/h2>\n<p>gn check <out_dir> [<label_pattern>] [--force]<br \/>\n\u8fd9\u4e2a\u5de5\u5177\u53ef\u4ee5\u7528\u6765\u68c0\u67e5\u5934\u6587\u4ef6\u4f9d\u8d56\u5173\u7cfb\u5f97\u6709\u6548\u6027\u3002<\/p>\n<pre><code>$ gn check out\/Default\/ net\nHeader dependency check OK<\/code><\/pre>\n<h2>gn help<\/h2>\n<p>\u5c55\u793a\u5e2e\u52a9\u4fe1\u606f\uff0c\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5173\u4e8e\u4e0a\u9762\u6240\u6709\u7684gn\u547d\u4ee4\uff0c\u53ca\u5185\u7f6e\u5f97targets\uff0c\u5185\u5efa\u5f97\u9884\u5b9a\u4e49\u53d8\u91cf\u7684\u6240\u6709\u76f8\u5173\u4fe1\u606f\u3002\u5982\uff1a<\/p>\n<pre><code>$ gn help<\/code><\/pre>\n<p>\u81ea CMake \u7248\u672c 2.8.8 \u8d77\uff0c\u53ef\u4ee5\u5728 Linux \u4e0a\u751f\u6210 Ninja \u6587\u4ef6\u7684\u5e7f\u6cdb\u4f7f\u7528\u7684\u5143\u6784\u5efa\u7cfb\u7edf\u3002 \u8f83\u65b0\u7248\u672c\u7684 CMake \u4e5f\u652f\u6301\u5728 Windows \u548c Mac OS X \u4e0a\u751f\u6210 Ninja \u6587\u4ef6\u3002<\/p>\n<h2>\u901a\u8fc7 GN \u6765\u751f\u6210 build.ninja<\/h2>\n<p>\u4ee5 GN \u4e2d\u6240\u81ea\u5e26\u7684\u4f8b\u5b50 <a href=\"https:\/\/gn.googlesource.com\/gn\/+\/refs\/heads\/main\/examples\/simple_build\/\">simple build<\/a> \u4e3a\u4f8b<\/p>\n<ul>\n<li>\u201c.gn\u201d<\/li>\n<\/ul>\n<pre><code># The location of the build configuration file.\nbuildconfig = &quot;\/\/build\/BUILDCONFIG.gn&quot;\n<\/code><\/pre>\n<ul>\n<li>build\/BUILDCONFIG.gn<\/li>\n<\/ul>\n<pre><code># Copyright 2014 The Chromium Authors. All rights reserved.\n# Use of this source code is governed by a BSD-style license that can be\n# found in the LICENSE file.\n\nif (target_os == &quot;&quot;) {\n  target_os = host_os\n}\nif (target_cpu == &quot;&quot;) {\n  target_cpu = host_cpu\n}\nif (current_cpu == &quot;&quot;) {\n  current_cpu = target_cpu\n}\nif (current_os == &quot;&quot;) {\n  current_os = target_os\n}\n\nis_linux = host_os == &quot;linux&quot; &amp;&amp; current_os == &quot;linux&quot; &amp;&amp; target_os == &quot;linux&quot;\nis_mac = host_os == &quot;mac&quot; &amp;&amp; current_os == &quot;mac&quot; &amp;&amp; target_os == &quot;mac&quot;\n\n# All binary targets will get this list of configs by default.\n_shared_binary_target_configs = [ &quot;\/\/build:compiler_defaults&quot; ]\n\n# Apply that default list to the binary target types.\nset_defaults(&quot;executable&quot;) {\n  configs = _shared_binary_target_configs\n\n  # Executables get this additional configuration.\n  configs += [ &quot;\/\/build:executable_ldconfig&quot; ]\n}\nset_defaults(&quot;static_library&quot;) {\n  configs = _shared_binary_target_configs\n}\nset_defaults(&quot;shared_library&quot;) {\n  configs = _shared_binary_target_configs\n}\nset_defaults(&quot;source_set&quot;) {\n  configs = _shared_binary_target_configs\n}\n\nset_default_toolchain(&quot;\/\/build\/toolchain:gcc&quot;)\n<\/code><\/pre>\n<ul>\n<li>build\/BUILD.gn<\/li>\n<\/ul>\n<pre><code># Copyright 2014 The Chromium Authors. All rights reserved.\n# Use of this source code is governed by a BSD-style license that can be\n# found in the LICENSE file.\n\nconfig(&quot;compiler_defaults&quot;) {\n  if (current_os == &quot;linux&quot;) {\n    cflags = [\n      &quot;-fPIC&quot;,\n      &quot;-pthread&quot;,\n    ]\n  }\n}\n\nconfig(&quot;executable_ldconfig&quot;) {\n  if (!is_mac) {\n    ldflags = [\n      &quot;-Wl,-rpath=\\$ORIGIN\/&quot;,\n      &quot;-Wl,-rpath-link=&quot;,\n    ]\n  }\n}\n<\/code><\/pre>\n<ul>\n<li>BUILD.gn<\/li>\n<\/ul>\n<pre><code># Copyright 2014 The Chromium Authors. All rights reserved.\n# Use of this source code is governed by a BSD-style license that can be\n# found in the LICENSE file.\n\nexecutable(&quot;hello&quot;) {\n  sources = [ &quot;hello.cc&quot; ]\n\n  deps = [\n    &quot;:hello_shared&quot;,\n    &quot;:hello_static&quot;,\n  ]\n}\n\nshared_library(&quot;hello_shared&quot;) {\n  sources = [\n    &quot;hello_shared.cc&quot;,\n    &quot;hello_shared.h&quot;,\n  ]\n\n  defines = [ &quot;HELLO_SHARED_IMPLEMENTATION&quot; ]\n}\n\nstatic_library(&quot;hello_static&quot;) {\n  sources = [\n    &quot;hello_static.cc&quot;,\n    &quot;hello_static.h&quot;,\n  ]\n}\n<\/code><\/pre>\n<h1>\u53c2\u8003\u8d44\u6599<\/h1>\n<ul>\n<li>Ninja \u624b\u518c: <a href=\"https:\/\/ninja-build.org\/manual.html\">https:\/\/ninja-build.org\/manual.html<\/a><\/li>\n<li>GN \u5feb\u901f\u4e0a\u624b\uff1a<a href=\"https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/quick_start.md\">https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/quick_start.md<\/a><\/li>\n<li>GN \u53c2\u8003\u624b\u518c\uff1a<a href=\"https:\/\/gn.googlesource.com\/gn\/+\/master\/docs\/reference.md\">https:\/\/gn.googlesource.com\/gn\/+\/master\/docs\/reference.md<\/a><\/li>\n<li>Using GN Build PPT: <a href=\"https:\/\/docs.google.com\/presentation\/d\/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo\/htmlpresent\">https:\/\/docs.google.com\/presentation\/d\/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo\/htmlpresent<\/a><\/li>\n<li><a href=\"https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/faq.md\">GN Frequently asked questions<\/a><\/li>\n<li><a href=\"https:\/\/gn.googlesource.com\/gn\/+\/main\/docs\/reference.md\">GN Reference<\/a><\/li>\n<\/ul>\n<p>\u6ce8\uff1a\u6709\u4e9b\u8fde\u63a5\u9700\u8981\u7ffb\u5899<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ninja Ninja \u539f\u610f\u662f\u5fcd\u8005\u7684\u610f\u601d\uff0c\u5b83\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u901f\u5ea6\u7684\u5c0f\u578b\u6784\u5efa\u5de5\u5177\u3002\u5b83\u662f\u4e00\u4e2a\u6784\u5efa\u7cfb\u7edf\u3002 \u5b83\u5c06\u6587\u4ef6\u7684\u76f8\u4e92\u4f9d\u8d56\u5173\u7cfb\uff08\u901a\u5e38\u662f\u6e90\u4ee3\u7801\u548c\u8f93\u51fa\u53ef\u6267\u884c\u6587\u4ef6\uff09\u4f5c\u4e3a\u8f93\u5165\uff0c\u5e76\u5feb\u901f\u7f16\u6392\u6784\u5efa\u5b83\u4eec\u3002 \u8fd0\u884cNinja\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u5b83\u4f1a\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u67e5\u627e\u540d\u4e3a build.ninja \u7684\u6587\u4ef6\u5e76\u6784\u5efa\u6240\u6709\u8fc7\u65f6\u7684\u76ee\u6807\u3002 \u60a8\u53ef\u4ee5\u6307\u5b9a\u8981\u6784\u5efa\u7684\u76ee\u6807\uff08\u6587\u4ef6\uff09\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u3002 \u8fd8\u6709\u4e00\u4e2a\u7279\u6b8a\u7684\u8bed\u6cd5 target^ \u7528\u4e8e\u5c06\u76ee\u6807\u6307\u5b9a\u4e3a\u67d0\u4e2a\u89c4\u5219\u7684\u7b2c\u4e00\u4e2a\u8f93\u51fa\uff0c\u5176\u4e2d\u5305\u542b\u60a8\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u7684\u6e90\uff08\u5982\u679c\u5b58\u5728\uff09\u3002 \u4f8b\u5982\uff0c\u5982\u679c\u60a8\u5c06\u76ee\u6807\u6307\u5b9a\u4e3a foo.c^\uff0c\u90a3\u4e48 foo.o \u5c06\u88ab\u6784\u5efa\uff08\u5047\u8bbe\u60a8\u7684\u6784\u5efa\u6587\u4ef6\u4e2d\u6709\u8fd9\u4e9b\u76ee\u6807\uff09\u3002 \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u4e0d\u9700\u8981\u624b\u5199 ninja \u6587\u4ef6\uff0c\u901a\u8fc7 gn \u6216 cmake \u6765\u63cf\u8ff0\u9879\u76ee\u7ed3\u6784\u548c\u4f9d\u8d56\u5173\u7cfb\uff0c\u518d\u901a\u8fc7\u5b83\u4eec\u6765\u751f\u6210 build.ninja \u6587\u4ef6 \u8be6\u89c1Ninja \u624b\u518c &#8211; https:\/\/ninja-build.org\/manual.html\uff0c Example byteorder.c #include &lt;stdio.h&gt; int main(int argc, char **argv) { union { short s; char c[sizeof(short)]; }un; un.s = 0x0102; if (sizeof(short) == 2) { if (un.c[0] [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=315\" title=\"Permanent Link to: \u7528 Ninja and GN \u6765\u52a0\u901f C++\u6784\u5efa\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-315","post","type-post","status-publish","format-standard","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=315"}],"version-history":[{"count":21,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions"}],"predecessor-version":[{"id":645,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/315\/revisions\/645"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}