{"id":95,"date":"2025-06-26T21:31:51","date_gmt":"2025-06-26T13:31:51","guid":{"rendered":"http:\/\/www.lhh-redbean.cn\/?p=95"},"modified":"2025-09-28T08:38:48","modified_gmt":"2025-09-28T00:38:48","slug":"vscode%e7%a5%9e%e5%99%a8-bear","status":"publish","type":"post","link":"http:\/\/www.lhh-redbean.cn\/index.php\/2025\/06\/26\/vscode%e7%a5%9e%e5%99%a8-bear\/","title":{"rendered":"Vscode\u795e\u5668\u2014\u2014bear"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5f00\u53d1\u5927\u578bC\u8bed\u8a00\u9879\u76ee\u65f6\uff0c\u7ecf\u5e38\u9700\u8981\u7528make\u7b49\u5de5\u5177\u6765\u534f\u52a9\u81ea\u52a8\u5316\u6784\u5efa\u9879\u76ee\uff0c\u8fd9\u65f6vscode\u7684\u4ee3\u7801\u8df3\u8f6c\u548c\u9ad8\u4eae\u68c0\u67e5\u4f1a\u53d8\u5f97\u6781\u5ea6\u6df7\u4e71\uff0c\u4e25\u91cd\u5f71\u54cd\u5f00\u53d1\u3002\u5bfc\u81f4\u8fd9\u4e2a\u73b0\u8c61\u7684\u6838\u5fc3\u539f\u56e0\u662f\uff0cvscode\u65e0\u6cd5\u5f97\u77e5\u4f60\u7684\u9879\u76ee\u6784\u5efa\u4f7f\u7528\u4e86\u54ea\u4e9b\u6e90\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u6765\u7ecf\u9ad8\u4eba\u4ecb\u7ecd\uff0c\u53d1\u73b0\u4e86bear\u8fd9\u4e2a\u795e\u5947\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u6839\u636emake\u7684\u8def\u5f84\uff0c\u751f\u6210\u4ee3\u7801\u7f16\u8bd1\u6784\u5efa\u4f9d\u8d56\u7684.json\u6587\u4ef6\u3002\u53ea\u9700\u5728vscode\u7684C\/C++\u5f00\u53d1\u76f8\u5173\u63d2\u4ef6\u7684\u914d\u7f6e.json\u6587\u4ef6\u4e2d\uff0c\u4fee\u6539\u5bf9\u5e94\u9009\u9879\uff0c\u5bfc\u5165bear\u751f\u6210\u7684\u914d\u7f6e.json\u6587\u4ef6\u5373\u53ef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u5927\u81f4\u4ecb\u7ecdbear\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u751f\u6210\u914d\u7f6e.json\u6587\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7b80\u5355\u7684\u4f7f\u7528\u65b9\u5f0f\u5c31\u662f\u76f4\u63a5\u5728\u9879\u76eeMakefile\u76ee\u5f55\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ make clean           # \u5efa\u8bae\u5148\u6e05\u7406\u518d\u6355\u83b7\uff0c\u4ee5\u514dbear\u6ca1\u6709\u6355\u83b7\u5230\u6240\u6709\u9700\u8981make\u7684\u6587\u4ef6\n$ bear -- make         # \u666e\u901a\u7f16\u8bd1\n$ bear -- make &#91;args]  # \u5e26\u53c2\u6570\u7684\u7f16\u8bd1<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br>\u968f\u540e\u4f1a\u5728\u8be5\u9879\u76ee\u76ee\u5f55\u4e0b\uff0c\u4ea7\u751f\u4e00\u4e2acompile_commands.json\u6587\u4ef6<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u5bfc\u5165Vscode<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5Microsoft C\/C++\u7cfb\u5217\u63d2\u4ef6\u4e3a\u4f8b\uff0c\u76f4\u63a5\u6253\u5f00.vscode\/c_cpp_properties.json\uff0c\u6dfb\u52a0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\"configurations\": &#91;\n    {\n        \"compileCommands\": \"project\/dir\/compile_commands.json\",\n    }\n],<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\u5c31\u53ef\u4ee5<s>\u7edd\u671b\u5730debug<\/s>\u5f00\u5fc3\u5730\u4ee3\u7801\u8df3\u8f6c\u5566<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u4f46\u662f<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u6b21\u90fd\u8981\u624b\u52a8\u8f93\u5165bear\u4ee3\u7801\uff0c\u66f4\u6539\u9879\u76ee\u8fd8\u8981\u624b\u52a8\u7ed9vscode\u5bfc\u5165\u65b0\u7684compile_commands.json<br>\u4e5f\u2014\u2014\u592a\u2014\u2014\u9ebb\u2014\u2014\u70e6\u2014\u2014\u4e86\u2014\u2014\u5427<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u4ee5\u76f4\u63a5\u628a\u6211\u7528\u7684\u7b80\u5355<s>\u5b89\u5168\u6027\u4e3a0<\/s>\u5c0f\u811a\u672c\u5f00\u6e90\u51fa\u6765\uff0c\u5927\u5bb6\u51d1\u5408\u7740\u7528<br>\u6ca1\u4f20github\uff0c\u56e0\u4e3a\u6211\u61d2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u65b9\u6cd5\uff1a<br>bear-setup [&#8211;path=&lt;\u6307\u5b9a\u8def\u5f84&gt;\uff0c\u5982\u679c\u8be5\u9009\u9879\u4e3a\u7a7a\u5219\u9ed8\u8ba4\u4e3adir\u53d8\u91cf\u4e2d\u7684\u8def\u5f84] make [\u4f60\u81ea\u5df1\u7684make \u53c2\u6570]<br>\u6bd4\u5982\u6211\u8981\u6784\u5efa\u6211\u7684make run<br>\u76f4\u63a5bear-setup make run<br>\u5c31\u53ef\u4ee5\u5728\u4f60\u60f3\u8981\u7684\u5730\u65b9\u4ea7\u751fcompile_commands.json\uff0c\u65e0\u9700\u9891\u7e41\u4fee\u6539vscode\u8bbe\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env bash\nbear-setup() {\n    local dir=\"\"    # \u6b64\u5904\u8f93\u5165\u4f60\u7684\u76ee\u6807\u8f93\u51fa\u76ee\u5f55\n    local help_msg=\"Usage: bear-setup &#91;--path=&lt;output_dir&gt;] make-command &#91;make-args...]\"\n\n    while &#91;&#91; $# -gt 0 ]]; do\n        case \"$1\" in\n            --path=*)\n                dir=\"${1#*=}\"\n                shift\n                ;;\n            --path)\n                &#91;&#91; $# -ge 2 ]] || { echo \"Error: --path requires an argument\"; echo \"$help_msg\"; return 1; }\n                dir=\"$2\"\n                shift 2\n                ;;\n            --help)\n                echo \"$help_msg\"\n                return 0\n                ;;\n            *)\n                break\n                ;;\n        esac\n    done\n\n    # \u9a8c\u8bc1\u5269\u4f59\u53c2\u6570\u662f\u5426\u5305\u542bmake\u547d\u4ee4\n    if &#91;&#91; $# -eq 0 ]]; then\n        echo \"Error: Missing make command\"\n        echo \"$help_msg\"\n        return 1\n    fi\n\n    dir=\"${dir%\/}\"\n    local output=\"$dir\/compile_commands.json\"\n    \n    # \u786e\u4fdd\u76ee\u5f55\u5b58\u5728\n    mkdir -p \"$dir\" || return 1\n\n    rm -f \"$output\"\n    make clean\n    bear --output \"$output\" -- \"$@\"\n    echo \"bear output: $output\"\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5f00\u53d1\u5927\u578bC\u8bed\u8a00\u9879\u76ee\u65f6\uff0c\u7ecf\u5e38\u9700\u8981&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[16],"class_list":["post-95","post","type-post","status-publish","format-standard","hentry","category-tools","tag-eztools"],"_links":{"self":[{"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/posts\/95","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/comments?post=95"}],"version-history":[{"count":4,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/posts\/95\/revisions"}],"predecessor-version":[{"id":126,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/posts\/95\/revisions\/126"}],"wp:attachment":[{"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/media?parent=95"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/categories?post=95"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.lhh-redbean.cn\/index.php\/wp-json\/wp\/v2\/tags?post=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}