{"id":629,"date":"2024-08-05T02:56:35","date_gmt":"2024-08-04T18:56:35","guid":{"rendered":"https:\/\/vm1.go2see.me\/?p=629"},"modified":"2024-08-05T02:56:35","modified_gmt":"2024-08-04T18:56:35","slug":"vscode-in-macos-setting","status":"publish","type":"post","link":"https:\/\/vm1.go2see.me\/?p=629","title":{"rendered":"VSCode in macOS setting"},"content":{"rendered":"<h1>\u5728Visual Studio Code\u4e2d\u4f7f\u7528Clang<\/h1>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u5c07\u5728macOS\u4e0a\u914d\u7f6eVisual Studio Code\u4ee5\u4f7f\u7528Clang\/LLVM\u7de8\u8b6f\u5668\u548c\u5075\u932f\u7a0b\u5f0f\u3002<\/p>\n<p>\u914d\u7f6eVS Code\u5f8c\uff0c\u60a8\u5c07\u5728VS Code\u4e2d\u7de8\u8b6f\u548c\u9664\u932fC++\u7a0b\u5f0f\u3002 \u672c\u6559\u7a0b\u6c92\u6709\u6559\u4f60Clang\u6216C++\u8a9e\u8a00\u3002 \u5c0d\u65bc\u9019\u4e9b\u4e3b\u984c\uff0c\u7db2\u8def\u4e0a\u6709\u5f88\u591a\u5f88\u597d\u7684\u8cc7\u6e90\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6709\u4efb\u4f55\u554f\u984c\uff0c\u8acb\u96a8\u6642\u5728<a href=\"https:\/\/github.com\/microsoft\/vscode-docs\/issues\">VS Code\u6587\u4ef6\u5132\u5b58\u5eab<\/a>\u4e2d\u70ba\u672c\u6559\u7a0b\u63d0\u4ea4\u554f\u984c\u3002<\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_prerequisites\">\u5148\u6c7a\u689d\u4ef6<\/a><\/h2>\n<p>\u8981\u6210\u529f\u5b8c\u6210\u672c\u6559\u7a0b\uff0c\u60a8\u5fc5\u9808\u5b8c\u6210\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li><a href=\"https:\/\/code.visualstudio.com\/docs\/setup\/mac\">\u5728macOS\u4e0a<\/a>\u5b89\u88dd<a href=\"https:\/\/code.visualstudio.com\/docs\/setup\/mac\">Visual Studio Code<\/a>\u3002<\/li>\n<li>\u5b89\u88dd<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools\">VS Code<\/a>\u7684<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=ms-vscode.cpptools\">C++\u64f4\u5145\u5957\u4ef6<\/a>\u3002 \u60a8\u53ef\u4ee5\u900f\u904e\u5728\u64f4\u5145\u5957\u4ef6\u6aa2\u8996\uff08\u21e7\u2318<strong>X<\/strong>\uff09\u4e2d\u641c\u5c0b\u201cC++\u201d\u4f86\u5b89\u88ddC\/C++\u64f4\u5145\u5957\u4ef6\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/cpp\/cpp-extension.png\" alt=\"C\/C++\u64f4\u5145\u5957\u4ef6\" \/><\/li>\n<\/ol>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_ensure-clang-is-installed\">\u78ba\u4fdd\u5b89\u88dd\u4e86Clang<\/a><\/h3>\n<p>\u60a8\u7684Mac\u4e0a\u53ef\u80fd\u5df2\u7d93\u5b89\u88dd\u4e86Clang\u3002 \u8981\u9a57\u8b49\u5b83\u662f\u5426\u662f\uff0c\u8acb\u958b\u555fmacOS\u201c\u7d42\u7aef\u201d\u8996\u7a97\uff0c\u7136\u5f8c\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>clang --version<\/code><\/pre>\n<p>\u5982\u679c\u672a\u5b89\u88ddClang\uff0c\u8acb\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\u4f86\u5b89\u88dd\u547d\u4ee4\u884c\u958b\u767c\u4eba\u54e1\u5de5\u5177\uff0c\u5176\u4e2d\u5305\u62ecClang\uff1a<\/p>\n<pre><code>xcode-select --install<\/code><\/pre>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_create-hello-world-app\">\u5efa\u7acbHello World\u61c9\u7528\u7a0b\u5f0f<\/a><\/h2>\n<p>\u5f9emacOS\u7d42\u7aef\uff0c\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>projects<\/code>\u7684\u7a7a\u8cc7\u6599\u593e\uff0c\u60a8\u53ef\u4ee5\u5728\u5176\u4e2d\u5132\u5b58\u6240\u6709VS Code\u5c08\u6848\uff0c\u7136\u5f8c\u5efa\u7acb\u4e00\u500b\u540d\u70ba <code>helloworld<\/code>\u7684\u5b50\u8cc7\u6599\u593e\uff0c\u5c0e\u822a\u5230\u8a72\u8cc7\u6599\u593e\uff0c\u4e26\u900f\u904e\u5728\u7d42\u7aef\u8996\u7a97\u4e2d\u8f38\u5165\u4ee5\u4e0b\u547d\u4ee4\u5728\u8a72\u8cc7\u6599\u593e\u4e2d\u958b\u555fVS Code\uff1a<\/p>\n<pre><code>mkdir projects\ncd projects\nmkdir helloworld\ncd helloworld\ncode .<\/code><\/pre>\n<p><code>code .<\/code>\u547d\u4ee4\u5728\u7576\u524d\u5de5\u4f5c\u8cc7\u6599\u593e\u4e2d\u958b\u555fVS\u7a0b\u5f0f\uff0c\u8a72\u8cc7\u6599\u593e\u5c07\u6210\u70ba\u60a8\u7684\u201c\u5de5\u4f5c\u5340\u201d\u3002 \u5728\u60a8\u700f\u89bd\u6559\u7a0b\u6642\uff0c\u5728\u5de5\u4f5c\u5340\u7684 <code>.vscode<\/code>\u8cc7\u6599\u593e\u4e2d\u5efa\u7acb\u4e86\u4e09\u500b\u6a94\u6848\uff1a<\/p>\n<ul>\n<li><code>tasks.json<\/code>\uff08\u7de8\u8b6f\u5668\u69cb\u5efa\u8a2d\u5b9a\uff09<\/li>\n<li><code>launch.json<\/code>\uff08\u5075\u932f\u7a0b\u5f0f\u8a2d\u5b9a\uff09<\/li>\n<li><code>c_cpp_properties.json<\/code>\uff08\u7de8\u8b6f\u5668\u8def\u5f91\u548cIntelliSense\u8a2d\u5b9a\uff09<\/li>\n<\/ul>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_add-a-hello-world-source-code-file\">\u65b0\u589e\u4e00\u500bhello world\u6e90\u7a0b\u5f0f\u6a94\u6848<\/a><\/h3>\n<p>\u5728\u6a94\u6848\u8cc7\u6e90\u7ba1\u7406\u5668\u6a19\u984c\u6b04\u4e2d\uff0c\u9078\u64c7\u201c <strong>\u65b0\u5efa\u6a94\u6848<\/strong> \u201d\u6309\u9215\uff0c\u4e26\u5c07\u6a94\u6848\u547d\u540d\u70ba <code>helloworld.cpp<\/code>\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/msvc\/new-file-button.png\" alt=\"\u65b0\u6a94\u6848\u6a19\u984c\u6b04\u6309\u9215\" \/><\/p>\n<p>\u8cbc\u4e0a\u4ee5\u4e0b\u6e90\u7a0b\u5f0f\uff1a<\/p>\n<pre><code>#include<iostream>\n#include<vector>\n#include<string>\n\nusingnamespacestd;\n\nintmain()\n{\n    vector<string> msg {\"Hello\", \"C++\", \"World\", \"from\", \"VS Code\", \"and the C++ extension!\"};\n\nfor (const string& word : msg)\n    {\n        cout << word <<\" \";\n    }\n    cout << endl;\n}<\/code><\/pre>\n<p>\u73fe\u5728\u6309\u2318<strong>S<\/strong>\u5132\u5b58\u6a94\u6848\u3002 \u8acb\u6ce8\u610f\uff0c\u60a8\u7684\u6a94\u6848\u5217\u5728VS Code\u5074\u6b04<strong>\u7684\u6a94\u6848\u8cc7\u6e90\u7ba1\u7406\u5668<\/strong>\u6aa2\u8996\uff08\u21e7\u2318<strong>E<\/strong>\uff09\u4e2d\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/msvc\/file-explorer.png\" alt=\"\u6a94\u6848\u8cc7\u6e90\u7ba1\u7406\u5668\" \/><\/p>\n<p>\u60a8\u9084\u53ef\u4ee5\u900f\u904e\u9078\u64c7 <strong>\u6a94\u6848<\/strong> &gt;<strong>\u81ea\u52d5\u5132\u5b58\u4f86<\/strong>\u555f\u7528<a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/codebasics#_save-auto-save\">\u81ea\u52d5\u5132\u5b58<\/a>\u4f86\u81ea\u52d5\u5132\u5b58\u6a94\u6848\u66f4\u6539\u3002 \u60a8\u53ef\u4ee5\u5728VS Code<a href=\"https:\/\/code.visualstudio.com\/docs\/getstarted\/userinterface\">\u4f7f\u7528\u8005\u4ecb\u9762\u6587\u4ef6<\/a>\u4e2d\u77ad\u89e3\u6709\u95dc\u5176\u4ed6\u6aa2\u8996\u7684\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n<blockquote>\n<p><strong>\u6ce8\u610f<\/strong> \uff1a\u7576\u60a8\u5132\u5b58\u6216\u958b\u555fC++\u6a94\u6848\u6642\uff0c\u60a8\u53ef\u80fd\u6703\u770b\u5230\u4f86\u81eaC\/C++\u64f4\u5145\u5957\u4ef6\u7684\u95dc\u65bcInsiders\u7248\u672c\u53ef\u7528\u6027\u7684\u901a\u77e5\uff0c\u8a72\u901a\u77e5\u5141\u8a31\u60a8\u6e2c\u8a66\u65b0\u529f\u80fd\u548c\u4fee\u5fa9\u3002 \u60a8\u53ef\u4ee5\u900f\u904e\u9078\u64c7 <code>X<\/code>\uff08 <strong>\u6e05\u9664\u901a\u77e5<\/strong> \uff09\u4f86\u5ffd\u7565\u6b64\u901a\u77e5\u3002<\/p>\n<\/blockquote>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_explore-intellisense\">\u63a2\u7d22IntelliSense<\/a><\/h2>\n<p><a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/intellisense\">IntelliSense<\/a>\u662f\u4e00\u500b\u5de5\u5177\uff0c\u900f\u904e\u65b0\u589e\u7a0b\u5f0f\u5b8c\u6210\u3001\u5f15\u6578\u8cc7\u8a0a\u3001\u5feb\u901f\u8cc7\u8a0a\u548c\u6210\u54e1\u5217\u8868\u7b49\u7a0b\u5f0f\u7de8\u8f2f\u529f\u80fd\uff0c\u5e6b\u52a9\u60a8\u66f4\u5feb\u3001\u66f4\u9ad8\u6548\u5730\u5beb\u7a0b\u5f0f\u3002<\/p>\n<p>\u8981\u6aa2\u8996IntelliSense\u7684\u64cd\u4f5c\uff0c\u8acb\u5c07\u6ed1\u9f20\u61f8\u505c\u5728 <code>vector<\/code>\u6216 <code>string<\/code>\u4e0a\u4ee5\u6aa2\u8996\u5176\u578b\u5225\u8cc7\u8a0a\u3002 \u5982\u679c\u60a8\u5728\u7b2c10\u884c\u9375\u5165 <code>msg.<\/code>\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u8981\u547c\u53eb\u7684\u63a8\u85a6\u6210\u54e1\u51fd\u5f0f\u7684\u5b8c\u6210\u5217\u8868\uff0c\u9019\u4e9b\u51fd\u5f0f\u90fd\u7531IntelliSense\u751f\u6210\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/wsl\/msg-intellisense.png\" alt=\"\u8a9e\u53e5\u5b8c\u6210IntelliSense\" \/><\/p>\n<p>\u60a8\u53ef\u4ee5\u6309<strong>Tab<\/strong>\u9375\u63d2\u5165\u6240\u9078\u6210\u54e1\u3002 \u7136\u5f8c\uff0c\u7576\u60a8\u65b0\u589e\u958b\u982d\u7684\u62ec\u865f\u6642\uff0c\u6703\u986f\u793a\u6709\u95dc\u51fd\u5f0f\u6240\u9700\u7684\u5f15\u6578\u7684\u8cc7\u8a0a\u3002<\/p>\n<p>\u5982\u679cIntelliSense\u5c1a\u672a\u914d\u7f6e\uff0c\u8acb\u958b\u555f\u547d\u4ee4\u8abf\u8272\u76e4\uff08\u21e7\u2318<strong>P<\/strong>\uff09\u4e26\u8f38\u5165 <strong>\u9078\u64c7IntelliSense\u914d\u7f6e<\/strong> \u3002 \u5f9e\u7de8\u8b6f\u5668\u7684\u4e0b\u62c9\u9078\u55ae\u4e2d\uff0c\u9078\u64c7 <code>Use clang++<\/code>\u9032\u884c\u914d\u7f6e\u3002 \u66f4\u591a\u8cc7\u8a0a\u53ef\u4ee5\u5728<a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/configure-intellisense\">IntelliSense\u914d\u7f6e\u6587\u4ef6<\/a>\u4e2d\u627e\u5230\u3002<\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_run-helloworldcpp\">\u57f7\u884chelloworld.cpp<\/a><\/h2>\n<p>\u8acb\u8a18\u4f4f\uff0cC++\u64f4\u5145\u5957\u4ef6\u4f7f\u7528\u60a8\u5b89\u88dd\u5728\u6a5f\u5668\u4e0a\u7684C++\u7de8\u8b6f\u5668\u4f86\u69cb\u5efa\u7a0b\u5f0f\u3002 \u5728\u5617\u8a66\u5728VS\u7a0b\u5f0f\u4e2d\u57f7\u884c\u548cdebughelloworld <code>helloworld.cpp<\/code>\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5b89\u88dd\u4e86C++\u7de8\u8b6f\u5668\uff0c\u5982Clang\u3002<\/p>\n<ol>\n<li>\u958b\u555f <code>helloworld.cpp<\/code>\uff0c\u4f7f\u5176\u6210\u70ba\u6d3b\u52d5\u6a94\u6848\u3002<\/li>\n<li>\u6309\u4e0b\u7de8\u8f2f\u5668\u53f3\u4e0a\u89d2\u7684\u64ad\u653e\u6309\u9215\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/playbutton\/run-play-button.png\" alt=\"helloworld.cpp\u7684\u87a2\u5e55\u622a\u5716\u548c\u64ad\u653e\u6309\u9215\" \/><\/li>\n<li>\u5f9e\u7cfb\u7d71\u4e0a\u6aa2\u6e2c\u5230\u7684\u7de8\u8b6f\u5668\u5217\u8868\u4e2d\u9078\u64c7 <strong>C\/C++\uff1aclang++\u69cb\u5efa\u548c\u9664\u932f\u6d3b\u52d5\u6a94\u6848<\/strong> \u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/build-and-debug-active-file.png\" alt=\"\u69cb\u5efa\u548c\u9664\u932f\u4efb\u52d9\" \/><\/li>\n<\/ol>\n<p>\u53ea\u6709\u5728\u7b2c\u4e00\u6b21\u57f7\u884c <code>helloworld.cpp<\/code>\u6642\uff0c\u60a8\u624d\u6703\u8981\u6c42\u60a8\u9078\u64c7\u7de8\u8b6f\u5668\u3002\u6b64\u7de8\u8b6f\u5668\u662f <code>tasks.json<\/code>\u6a94\u6848\u4e2d\u8a2d\u5b9a\u7684\u201c\u9810\u8a2d\u201d\u7de8\u8b6f\u5668\u3002<\/p>\n<ol start=\"4\">\n<li>\u69cb\u5efa\u6210\u529f\u5f8c\uff0c\u60a8\u7684\u7a0b\u5f0f\u8f38\u51fa\u5c07\u986f\u793a\u5728\u6574\u5408\u7684<strong>\u9664\u932f\u63a7\u5236\u6aaf<\/strong>\u4e2d\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/helloworld-debug-console-output.png\" alt=\"\u7a0b\u5f0f\u8f38\u51fa\u7684\u87a2\u5e55\u622a\u5716\" \/><\/li>\n<\/ol>\n<p>\u606d\u559c\u4f60\uff01 \u60a8\u525b\u525b\u5728VS\u7a0b\u5f0f\u4e2d\u57f7\u884c\u4e86\u7b2c\u4e00\u500bC++\u7a0b\u5f0f\uff01<\/p>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_understanding-tasksjson\">\u7406\u89e3\u4efb\u52d9.json<\/a><\/h3>\n<p>\u9996\u6b21\u57f7\u884c\u7a0b\u5f0f\u6642\uff0cC++\u64f4\u5145\u5957\u4ef6\u6703\u5efa\u7acb <code>tasks.json<\/code>\uff0c\u4f4d\u65bc\u5c08\u6848\u7684 <code>.vscode<\/code>\u8cc7\u6599\u593e\u4e2d\u3002<code>tasks.json<\/code>\u5132\u5b58\u69cb\u5efa\u914d\u7f6e\u3002<\/p>\n<p>\u4ee5\u4e0b\u662fmacOS\u4e0a <code>tasks.json<\/code>\u6a94\u6848\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>{\n\"tasks\": [\n    {\n\"type\": \"cppbuild\",\n\"label\": \"C\/C++: clang++ build active file\",\n\"command\": \"\/usr\/bin\/clang++\",\n\"args\": [\n\"-fcolor-diagnostics\",\n\"-fansi-escape-codes\",\n\"-g\",\n\"${file}\",\n\"-o\",\n\"${fileDirname}\/${fileBasenameNoExtension}\"\n      ],\n\"options\": {\n\"cwd\": \"${fileDirname}\"\n      },\n\"problemMatcher\": [\"$gcc\"],\n\"group\": {\n\"kind\": \"build\",\n\"isDefault\": true\n      },\n\"detail\": \"Task generated by Debugger.\"\n    }\n  ],\n\"version\": \"2.0.0\"\n}<\/code><\/pre>\n<blockquote>\n<p><strong>\u6ce8\u610f<\/strong> \uff1a\u60a8\u53ef\u4ee5\u5728<a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/variables-reference\">\u8b8a\u6578\u53c3\u8003<\/a>\u4e2d\u77ad\u89e3\u6709\u95dc <code>tasks.json<\/code>\u8b8a\u6578\u7684\u66f4\u591a\u8cc7\u8a0a\u3002<\/p>\n<\/blockquote>\n<p><code>command<\/code>\u8a2d\u5b9a\u6307\u5b9a\u8981\u57f7\u884c\u7684\u7a0b\u5f0f\u3002 \u5728\u9019\u7a2e\u60c5\u6cc1\u4e0b\uff0c\u90a3\u662f <code>clang++<\/code><\/p>\n<p><code>args<\/code>\u9663\u5217\u6307\u5b9a\u50b3\u905e\u7d66clang++\u7684\u547d\u4ee4\u884c\u5f15\u6578\u3002 \u9019\u4e9b\u5f15\u6578\u5fc5\u9808\u6309\u7167\u7de8\u8b6f\u5668\u9810\u671f\u7684\u9806\u5e8f\u6307\u5b9a\u3002<\/p>\n<p>This task tells the C++ compiler to take the active file (<code>${file}<\/code>), compile it, and create an output file (<code>-o<\/code>switch) in the current directory (<code>${fileDirname}<\/code>) with the same name as the active file but without the file extension (<code>${fileBasenameNoExtension}<\/code>). This process creates<strong> <\/strong><code>helloworld<\/code>.<\/p>\n<p><code>label<\/code>\u503c\u662f\u60a8\u5728\u4efb\u52d9\u5217\u8868\u4e2d\u770b\u5230\u7684\uff0c\u57fa\u65bc\u60a8\u7684\u500b\u4eba\u559c\u597d\u3002<\/p>\n<p><code>detail<\/code>\u503c\u662f\u4efb\u52d9\u5217\u8868\u4e2d\u4efb\u52d9\u7684\u63cf\u8ff0\u3002 \u66f4\u65b0\u6b64\u5b57\u4e32\u4ee5\u5c07\u5176\u8207\u985e\u4f3c\u4efb\u52d9\u5340\u5206\u958b\u4f86\u3002<\/p>\n<p><code>problemMatcher<\/code>\u503c\u9078\u64c7\u7528\u65bc\u5728\u7de8\u8b6f\u5668\u8f38\u51fa\u4e2d\u67e5\u8a62\u932f\u8aa4\u548c\u8b66\u544a\u7684\u8f38\u51fa\u89e3\u6790\u5668\u3002 \u5c0d\u65bcclang++\uff0c$<code>$gcc<\/code>\u554f\u984c\u5339\u914d\u5668\u6703\u7522\u751f\u6700\u4f73\u7d50\u679c\u3002<\/p>\n<p>\u5f9e\u73fe\u5728\u958b\u59cb\uff0c\u64ad\u653e\u6309\u9215\u7e3d\u662f\u5f9e <code>tasks.json<\/code>\u4e2d\u8b80\u53d6\uff0c\u4ee5\u77ad\u89e3\u5982\u4f55\u69cb\u5efa\u548c\u57f7\u884c\u7a0b\u5f0f\u3002 \u60a8\u53ef\u4ee5\u5728 <code>tasks.json<\/code>\u4e2d\u5b9a\u7fa9\u591a\u500b\u69cb\u5efa\u4efb\u52d9\uff0c\u4efb\u4f55\u88ab\u6a19\u8a18\u70ba\u9810\u8a2d\u4efb\u52d9\u7684\u4efb\u52d9\u90fd\u662f\u64ad\u653e\u6309\u9215\u4f7f\u7528\u7684\u4efb\u52d9\u3002 \u5982\u679c\u60a8\u9700\u8981\u66f4\u6539\u9810\u8a2d\u7de8\u8b6f\u5668\uff0c\u60a8\u53ef\u4ee5\u5728\u547d\u4ee4\u8abf\u8272\u76e4\u4e2d\u57f7\u884c <strong>\u4efb\u52d9\uff1a\u914d\u7f6e\u9810\u8a2d\u69cb\u5efa\u4efb\u52d9<\/strong> \u3002 \u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u4fee\u6539 <code>tasks.json<\/code>\u6a94\u6848\uff0c\u4e26\u900f\u904e\u66ff\u63db\u6b64\u6bb5\u4f86\u522a\u9664\u9810\u8a2d\u503c\uff1a<\/p>\n<pre><code>\"group\": {\n\"kind\": \"build\",\n\"isDefault\": true\n    },<\/code><\/pre>\n<p>\u7528\u9019\u500b\uff1a<\/p>\n<pre><code>\"group\": \"build\",<\/code><\/pre>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_modifying-tasksjson\">\u4fee\u6539\u4efb\u52d9.json<\/a><\/h3>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 <code>&quot;${workspaceFolder}\/*.cpp&quot;<\/code>\u800c\u4e0d\u662f <code>&quot;${file}&quot;<\/code>\u7b49\u5f15\u6578\u4fee\u6539 <code>tasks.json<\/code>\u4ee5\u69cb\u5efa\u591a\u500bC++\u6a94\u6848\u3002<strong> <\/strong>\u9019\u6703\u69cb\u5efa\u60a8\u7576\u524d\u8cc7\u6599\u593e\u4e2d\u7684\u6240\u6709 <code>.cpp<\/code>\u6a94\u6848\u3002 \u60a8\u9084\u53ef\u4ee5\u900f\u904e\u5c07 <code>&quot;${fileDirname}\/${fileBasenameNoExtension}&quot;<\/code>\u66ff\u63db\u70ba\u786c\u7de8\u78bc\u6a94\u540d\uff08\u4f8b\u5982 <code>&quot;${workspaceFolder}\/myProgram.out&quot;<\/code>\u4fee\u6539\u8f38\u51fa\u6a94\u540d\u3002<\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_debug-helloworldcpp\">\u9664\u932fhelloworld.cpp<\/a><\/h2>\n<p>\u8981\u9664\u932f\u60a8\u7684\u7a0b\u5f0f\uff0c<\/p>\n<ol>\n<li>\u56de\u5230 <code>helloworld.cpp<\/code>\uff0c\u4ee5\u4fbf\u5b83\u662f\u6d3b\u52d5\u6a94\u6848\u3002<\/li>\n<li>\u900f\u904e\u55ae\u64ca\u7de8\u8f2f\u5668\u908a\u8ddd\u6216\u4f7f\u7528\u7576\u524d\u884c\u4e0a\u7684F9\u4f86\u8a2d\u5b9a\u65b7\u9ede\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/playbutton\/cpp-breakpoint.png\" alt=\"helloworld.cpp\u4e2d\u65b7\u9ede\u7684\u87a2\u5e55\u622a\u5716\" \/><\/li>\n<li>\u5f9e\u64ad\u653e\u6309\u9215\u65c1\u908a\u7684\u4e0b\u62c9\u9078\u55ae\u4e2d\uff0c\u9078\u64c7 <strong>\u9664\u932fC\/C++\u6a94\u6848<\/strong> \u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/playbutton\/debug-cpp-file-play-button.png\" alt=\"\u64ad\u653e\u6309\u9215\u4e0b\u62c9\u9078\u55ae\u7684\u87a2\u5e55\u622a\u5716\" \/><\/li>\n<li>\u5f9e\u7cfb\u7d71\u4e0a\u6aa2\u6e2c\u5230\u7684\u7de8\u8b6f\u5668\u5217\u8868\u4e2d\u9078\u64c7 <strong>C\/C++\uff1aclang++\u69cb\u5efa\u548c\u9664\u932f\u6d3b\u52d5\u6a94\u6848<\/strong> \uff08\u53ea\u6709\u5728\u60a8\u7b2c\u4e00\u6b21\u57f7\u884c\u6216\u9664\u932f <code>helloworld.cpp<\/code>\u6642\u624d\u6703\u8981\u6c42\u60a8\u9078\u64c7\u7de8\u8b6f\u5668\uff09\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/build-and-debug-active-file.png\" alt=\"\u69cb\u5efa\u548c\u9664\u932f\u4efb\u52d9\" \/><\/li>\n<li>\u60a8\u5c07\u770b\u5230\u4efb\u52d9\u57f7\u884c\uff0c\u4e26\u5c07\u8f38\u51fa\u5217\u5370\u5230<strong>\u7d42\u7aef<\/strong>\u8996\u7a97\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/helloworld-terminal-output.png\" alt=\"\u4f60\u597d\uff0c\u4e16\u754c\u7d42\u7aef\u8f38\u51fa\" \/><\/li>\n<\/ol>\n<p>\u64ad\u653e\u6309\u9215\u6709\u5169\u7a2e\u6a21\u5f0f\uff1a<strong>\u57f7\u884cC\/C++\u6a94\u6848<\/strong>\u548c <strong>\u9664\u932fC\/C++\u6a94\u6848<\/strong> \u3002 \u9810\u8a2d\u662f\u4e0a\u6b21\u4f7f\u7528\u7684\u6a21\u5f0f\u3002 \u5982\u679c\u60a8\u5728\u64ad\u653e\u6309\u9215\u4e2d\u770b\u5230\u9664\u932f\u5716\u793a\uff0c\u60a8\u53ef\u4ee5\u9078\u64c7\u8981\u9664\u932f\u7684\u64ad\u653e\u6309\u9215\uff0c\u800c\u4e0d\u662f\u9078\u64c7\u4e0b\u62c9\u9078\u55ae\u9805\u3002<\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_explore-the-debugger\">\u63a2\u7d22\u5075\u932f\u7a0b\u5f0f<\/a><\/h2>\n<p>\u5728\u60a8\u958b\u59cb\u9010\u6b65\u5b8c\u6210\u7a0b\u5f0f\u4e4b\u524d\uff0c\u8b93\u6211\u5011\u82b1\u9ede\u6642\u9593\u6ce8\u610f\u4f7f\u7528\u8005\u4ecb\u9762\u7684\u5e7e\u500b\u8b8a\u5316\uff1a<\/p>\n<ul>\n<li>\u6574\u5408\u7d42\u7aef\u51fa\u73fe\u5728\u6e90\u7a0b\u5f0f\u7de8\u8f2f\u5668\u7684\u5e95\u90e8\u3002 \u5728\u201c <strong>\u9664\u932f\u63a7\u5236\u6aaf<\/strong> \u201d\u9078\u9805\u5361\u4e2d\uff0c\u60a8\u6703\u770b\u5230\u6307\u793a\u9664\u932f\u5668\u5df2\u555f\u52d5\u4e26\u57f7\u884c\u7684\u8f38\u51fa\u3002<\/li>\n<li>\u7de8\u8f2f\u5668\u7a81\u51fa\u986f\u793a\u60a8\u5728\u555f\u52d5\u5075\u932f\u7a0b\u5f0f\u4e4b\u524d\u8a2d\u5b9a\u65b7\u9ede\u7684\u884c\uff1a<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/playbutton\/breakpoint-debug.png\" alt=\"\u521d\u59cb\u65b7\u9ede\" \/><\/li>\n<li>\u6d3b\u52d5\u6b04\u4e2d\u7684\u201c <strong>\u57f7\u884c\u548c\u9664\u932f\u201d<\/strong> \u6aa2\u8996\u986f\u793a\u9664\u932f\u8cc7\u8a0a\u3002<\/li>\n<li>\u5728\u7a0b\u5f0f\u7de8\u8f2f\u5668\u7684\u9802\u90e8\uff0c\u6703\u51fa\u73fe\u4e00\u500b\u9664\u932f\u63a7\u5236\u9762\u677f\u3002 \u60a8\u53ef\u4ee5\u900f\u904e\u6293\u4f4f\u5de6\u5074\u7684\u9ede\u5728\u87a2\u5e55\u4e0a\u79fb\u52d5\u5b83\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/cpp\/debug-controls.png\" alt=\"\u9664\u932f\u63a7\u5236\" \/><\/li>\n<\/ul>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_step-through-the-code\">\u9010\u6b65\u700f\u89bd\u7a0b\u5f0f<\/a><\/h2>\n<p>\u73fe\u5728\u60a8\u5df2\u7d93\u6e96\u5099\u597d\u958b\u59cb\u9010\u6b65\u5b8c\u6210\u7a0b\u5f0f\u4e86\u3002<\/p>\n<ol>\n<li>\u5728\u9664\u932f\u63a7\u5236\u9762\u677f\u4e2d\u9078\u64c7<strong>Step over<\/strong>\u5716\u793a\uff0c\u4ee5\u4fbf\u7a81\u51fa\u986f\u793a <code>for (const string&amp; word : msg)<\/code>\u8a9e\u53e5\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/cpp\/step-over-button.png\" alt=\"\u8de8\u904e\u6309\u9215\" \/><br \/>\nThe<strong> **<\/strong>Step Over<strong> command skips over all the internal function calls within the<\/strong> <strong><code>vector<\/code> and<\/strong> <strong><code>string<\/code>classes that are invoked when the<\/strong> <strong><code>msg<\/code> variable is created and initialized. Notice the change in the<\/strong> <strong>**Variables<\/strong> window. The contents of<strong> <\/strong><code>msg<\/code> are visible because that statement has completed.<\/li>\n<li>\u518d\u6b21\u6309<strong>Step<\/strong>\u4ee5\u9032\u5165\u4e0b\u4e00\u500b\u8a9e\u53e5\uff08\u8df3\u904e\u6240\u6709\u57f7\u884c\u7684\u5167\u90e8\u7a0b\u5f0f\u4ee5\u521d\u59cb\u5316\u8ff4\u5708\uff09\u3002 \u73fe\u5728\uff0c<strong>\u8b8a\u6578<\/strong>\u8996\u7a97\u986f\u793a\u6709\u95dc\u8ff4\u5708\u8b8a\u6578\u7684\u8cc7\u8a0a\u3002<\/li>\n<li>\u518d\u6b21\u6309<strong>Step over<\/strong>\u4ee5\u57f7\u884c <code>cout<\/code>\u8a9e\u53e5\u3002<\/li>\n<li>\u5982\u679c\u60a8\u9858\u610f\uff0c\u60a8\u53ef\u4ee5\u7e7c\u7e8c\u6309\u201c <strong>\u6b65\u9a5f<\/strong> \u201d <strong>\uff0c<\/strong> \u76f4\u5230\u5411\u91cf\u4e2d\u7684\u6240\u6709\u55ae\u8a5e\u90fd\u5217\u5370\u5230\u63a7\u5236\u6aaf\u3002 \u4f46\u662f\uff0c\u5982\u679c\u60a8\u611f\u5230\u597d\u5947\uff0c\u8acb\u5617\u8a66\u6309\u201c <strong>\u6b65\u5165<\/strong> \u201d\u6309\u9215\u4f86\u9010\u6b65\u700f\u89bdC++\u6a19\u6e96\u5eab\u4e2d\u7684\u6e90\u7a0b\u5f0f\uff01<\/li>\n<\/ol>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_set-a-watch\">\u8a2d\u5b9a\u4e00\u500b\u624b\u9336<\/a><\/h2>\n<p>\u60a8\u53ef\u80fd\u60f3\u5728\u7a0b\u5f0f\u57f7\u884c\u6642\u8ddf\u8e64\u8b8a\u6578\u7684\u503c\u3002 \u60a8\u53ef\u4ee5\u900f\u904e\u5728\u8b8a\u6578\u4e0a\u8a2d\u5b9a<strong>\u624b\u9336<\/strong>\u4f86\u505a\u5230\u9019\u4e00\u9ede\u3002<\/p>\n<ol>\n<li>\u5c07\u63d2\u5165\u9ede\u653e\u5728\u74b0\u5167\u3002 \u5728\u201c <strong>\u624b\u9336<\/strong> \u201d\u8996\u7a97\u4e2d\uff0c\u9078\u64c7\u52a0\u865f\u4e26\u5728\u6587\u5b57\u6846\u4e2d\u9375\u5165 <code>word<\/code>\u3002 \u9019\u662f\u8ff4\u5708\u8b8a\u6578\u7684\u540d\u7a31\u3002 \u73fe\u5728\uff0c\u5728\u60a8\u9010\u6b65\u900f\u904e\u8ff4\u5708\u6642\u6aa2\u8996<strong>\u624b\u9336<\/strong>\u8996\u7a97\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/cpp\/watch-window.png\" alt=\"\u89c0\u5bdf\u8996\u7a97\" \/><\/li>\n<li>\u900f\u904e\u5728\u8ff4\u5708\u524d\u65b0\u589e\u6b64\u8a9e\u53e5\u4f86\u65b0\u589e\u53e6\u4e00\u500b\u624b\u9336\uff1a<code>int i = 0;<\/code>\u3002 \u7136\u5f8c\uff0c\u5728\u8ff4\u5708\u4e2d\uff0c\u65b0\u589e\u4ee5\u4e0b\u8a9e\u53e5\uff1a<code>++i;<\/code>\u3002 \u73fe\u5728\uff0c\u50cf\u5728\u4e0a\u4e00\u6b65\u4e2d\u4e00\u6a23\uff0c\u70ba <code>i<\/code>\u65b0\u589e\u4e00\u584a\u624b\u9336\u3002<\/li>\n<li>\u8981\u5728\u57f7\u884c\u66ab\u505c\u6642\u5feb\u901f\u6aa2\u8996\u4efb\u4f55\u8b8a\u6578\u7684\u503c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6ed1\u9f20\u6307\u6a19\u5c07\u6ed1\u9f20\u61f8\u505c\u5728\u5b83\u4e0a\u9762\u3002<br \/>\n<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/cpp\/mouse-hover.png\" alt=\"\u6ed1\u9f20\u61f8\u505c\" \/><\/li>\n<\/ol>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_customize-debugging-with-launchjson\">\u4f7f\u7528launch.json\u81ea\u5b9a\u7fa9\u9664\u932f<\/a><\/h2>\n<p>\u7576\u60a8\u4f7f\u7528\u64ad\u653e\u6309\u9215\u6216<strong>F5<\/strong>\u9032\u884c\u9664\u932f\u6642\uff0cC++\u64f4\u5145\u5957\u4ef6\u6703\u5be6\u6642\u5efa\u7acb\u52d5\u614b\u9664\u932f\u914d\u7f6e\u3002<\/p>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u60a8\u5e0c\u671b\u81ea\u5b9a\u7fa9\u9664\u932f\u914d\u7f6e\uff0c\u4f8b\u5982\u6307\u5b9a\u5f15\u6578\u5728\u57f7\u884c\u6642\u50b3\u905e\u7d66\u7a0b\u5f0f\u3002 \u60a8\u53ef\u4ee5\u5728 <code>launch.json<\/code>\u6a94\u6848\u4e2d\u5b9a\u7fa9\u81ea\u5b9a\u7fa9\u9664\u932f\u914d\u7f6e\u3002<\/p>\n<p>\u8981\u5efa\u7acb <code>launch.json<\/code>\uff0c\u8acb\u5f9e\u64ad\u653e\u6309\u9215\u4e0b\u62c9\u9078\u55ae\u4e2d\u9078\u64c7\u201c <strong>\u65b0\u589e\u9664\u932f\u914d\u7f6e<\/strong> \u201d\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/playbutton\/add-debug-configuration.png\" alt=\"\u65b0\u589e\u9664\u932f\u914d\u7f6e\u64ad\u653e\u6309\u9215\u9078\u55ae\" \/><\/p>\n<p>\u7136\u5f8c\uff0c\u60a8\u5c07\u770b\u5230\u5404\u7a2e\u9810\u5b9a\u7fa9\u7684\u9664\u932f\u914d\u7f6e\u7684\u4e0b\u62c9\u9078\u55ae\u3002 \u9078\u64c7 <strong>C\/C++\uff1aclang++\u69cb\u5efa\u548c\u9664\u932f\u6d3b\u52d5\u6a94\u6848<\/strong> \u3002<img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/build-and-debug-active-file.png\" alt=\"C++\u9664\u932f\u914d\u7f6e\u4e0b\u62c9\u5217\u8868\" \/><\/p>\n<p>VS Code\u5efa\u7acb\u4e86\u4e00\u500b <code>launch.json<\/code>\u6a94\u6848\uff0c\u770b\u8d77\u4f86\u50cf\u9019\u6a23\uff1a<\/p>\n<pre><code>{\n\"configurations\": [\n    {\n\"name\": \"C\/C++: clang++ build and debug active file\",\n\"type\": \"cppdbg\",\n\"request\": \"launch\",\n\"program\": \"${fileDirname}\/${fileBasenameNoExtension}\",\n\"args\": [],\n\"stopAtEntry\": false,\n\"cwd\": \"${fileDirname}\",\n\"environment\": [],\n\"externalConsole\": false,\n\"MIMode\": \"lldb\",\n\"preLaunchTask\": \"C\/C++: clang++ build active file\"\n    }\n  ],\n\"version\": \"2.0.0\"\n}<\/code><\/pre>\n<p>The<strong> <\/strong><code>program<\/code> setting specifies the program you want to debug. Here it is set to the active file folder<strong> <\/strong><code>${fileDirname}<\/code> and active filename<strong> <\/strong><code>${fileBasenameNoExtension}<\/code>, which if<strong> <\/strong><code>helloworld.cpp<\/code> is the active file will be<strong> <\/strong><code>helloworld<\/code>. The<strong> <\/strong><code>args<\/code> property is an array of arguments to pass to the program at runtime.<\/p>\n<p>\u9810\u8a2d\u60c5\u6cc1\u4e0b\uff0cC++\u64f4\u5145\u5957\u4ef6\u4e0d\u6703\u5411\u6e90\u7a0b\u5f0f\u65b0\u589e\u4efb\u4f55\u65b7\u9ede\uff0c<code>stopAtEntry<\/code>\u503c\u8a2d\u5b9a\u70ba <code>false<\/code>\u3002<\/p>\n<p>\u5c07 <code>stopAtEntry<\/code>\u503c\u66f4\u6539\u70ba <code>true<\/code>\uff0c\u4ee5\u4fbf\u5728\u60a8\u958b\u59cb\u9664\u932f\u6642\u4f7f\u5075\u932f\u7a0b\u5f0f\u5728 <code>main<\/code>\u65b9\u6cd5\u4e0a\u505c\u6b62\u3002<\/p>\n<p>\u78ba\u4fdd <code>preLaunchTask<\/code>\u503c\u8207 <code>tasks.json<\/code>\u6a94\u6848\u4e2d\u7684\u69cb\u5efa\u4efb\u52d9\u7684 <code>label<\/code>\u76f8\u5339\u914d\u3002<\/p>\n<blockquote>\n<p>\u5f9e\u73fe\u5728\u958b\u59cb\uff0c\u5728\u555f\u52d5\u7a0b\u5f0f\u9032\u884c\u9664\u932f\u6642\uff0c\u64ad\u653e\u6309\u9215\u548c<strong>F5<\/strong>\u5c07\u5f9e\u60a8\u7684 <code>launch.json<\/code>\u6a94\u6848\u4e2d\u8b80\u53d6\u3002<\/p>\n<\/blockquote>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_adding-additional-cc-settings\">\u65b0\u589e\u984d\u5916\u7684C\/C++\u8a2d\u5b9a<\/a><\/h2>\n<p>\u8981\u5c0dC\/C++\u64f4\u5145\u5957\u4ef6\u9032\u884c\u66f4\u591a\u63a7\u5236\uff0c\u8acb\u5efa\u7acb\u4e00\u500b <code>c_cpp_properties.json<\/code>\u6a94\u6848\uff0c\u8a72\u6a94\u6848\u5141\u8a31\u60a8\u66f4\u6539\u8a2d\u5b9a\uff0c\u5982\u7de8\u8b6f\u5668\u7684\u8def\u5f91\uff0c\u5305\u62ec\u8981\u7de8\u8b6f\u7684C++\u6a19\u6e96\uff08\u5982C++17\uff09\u7684\u8def\u5f91\u7b49\u3002<\/p>\n<p>\u900f\u904e\u57f7\u884c\u547d\u4ee4 <strong>C\/C++<\/strong> \u6aa2\u8996C\/C++\u914d\u7f6eUI <strong>\uff1a<\/strong> \u5f9e\u547d\u4ee4\u8abf\u8272\u76e4\uff08\u21e7\u2318<strong>P<\/strong>\uff09<strong>\u7de8\u8f2f\u914d\u7f6e\uff08UI\uff09\u3002<\/strong><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/mac-command-palette-configurations.png\" alt=\"\u547d\u4ee4\u8abf\u8272\u76e4\" \/><\/p>\n<p>\u9019\u5c07\u958b\u555f<strong>C\/C++\u914d\u7f6e<\/strong>\u9801\u9762\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/code.visualstudio.com\/assets\/docs\/cpp\/clang-mac\/intellisense-configurations-mac-clang.png\" alt=\"C++\u914d\u7f6e\" \/><\/p>\n<p>Visual Studio Code\u5c07\u9019\u4e9b\u8a2d\u5b9a\u653e\u7f6e\u5728 <code>.vscode\/c_cpp_properties.json<\/code>\u4e2d\u3002 \u5982\u679c\u60a8\u76f4\u63a5\u958b\u555f\u8a72\u6a94\u6848\uff0c\u5b83\u61c9\u8a72\u770b\u8d77\u4f86\u50cf\u9019\u6a23\uff1a<\/p>\n<pre><code>{\n\"configurations\": [\n    {\n\"name\": \"Mac\",\n\"includePath\": [\"${workspaceFolder}\/**\"],\n\"defines\": [],\n\"macFrameworkPath\": [\n\"\/Library\/Developer\/CommandLineTools\/SDKs\/MacOSX.sdk\/System\/Library\/Frameworks\"\n      ],\n\"compilerPath\": \"\/usr\/bin\/clang\",\n\"cStandard\": \"c11\",\n\"cppStandard\": \"c++17\",\n\"intelliSenseMode\": \"macos-clang-arm64\"\n    }\n  ],\n\"version\": 4\n}<\/code><\/pre>\n<p>\u50c5\u7576\u60a8\u7684\u7a0b\u5f0f\u5305\u542b\u4e0d\u5728\u5de5\u4f5c\u5340\u6216\u6a19\u6e96\u5eab\u8def\u5f91\u4e2d\u7684\u6a19\u982d\u6a94\u6848\u6642\uff0c\u60a8\u624d\u9700\u8981\u4fee\u6539<strong>\u5305\u542b\u8def\u5f91<\/strong>\u8a2d\u5b9a\u3002<\/p>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_compiler-path\">\u7de8\u8b6f\u5668\u8def\u5f91<\/a><\/h3>\n<p>\u8a72\u64f4\u5145\u5957\u4ef6\u4f7f\u7528 <code>compilerPath<\/code>\u8a2d\u5b9a\u4f86\u63a8\u65b7C++\u6a19\u6e96\u5eab\u982d\u6a94\u6848\u7684\u8def\u5f91\u3002 \u7576\u64f4\u5145\u5957\u4ef6\u77e5\u9053\u5728\u54ea\u88e1\u53ef\u4ee5\u627e\u5230\u9019\u4e9b\u6a94\u6848\u6642\uff0c\u5b83\u53ef\u4ee5\u63d0\u4f9b\u667a\u6167\u5b8c\u6210\u548c<strong>\u8f49\u5230\u5b9a\u7fa9<\/strong>\u5c0e\u822a\u7b49\u529f\u80fd\u3002<\/p>\n<p>The C\/C++ extension attempts to populate<strong> <\/strong><code>compilerPath<\/code> with the default compiler location based on what it finds on your system. The<strong> <\/strong><code>compilerPath<\/code> search order is:<\/p>\n<ul>\n<li>\u5df2\u77e5\u7de8\u8b6f\u5668\u540d\u7a31\u7684\u8def\u5f91\u3002 \u7de8\u8b6f\u5668\u5728\u5217\u8868\u4e2d\u986f\u793a\u7684\u9806\u5e8f\u53d6\u6c7a\u65bc\u60a8\u7684\u8def\u5f91\u3002<\/li>\n<li>\u7136\u5f8c\u641c\u5c0b\u786c\u7de8\u78bc\u7684Xcode\u8def\u5f91\uff0c\u4f8b\u5982 <code>\/Applications\/Xcode.app\/Contents\/Developer\/Toolchains\/XcodeDefault.xctoolchain\/usr\/bin\/<\/code><\/li>\n<\/ul>\n<p>\u6709\u95dc\u66f4\u591a\u8cc7\u8a0a\uff0c\u8acb\u53c3\u95b1<a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/configure-intellisense\">IntelliSense\u914d\u7f6e\u6587\u4ef6<\/a>\u3002<\/p>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_mac-framework-path\">Mac\u6846\u67b6\u8def\u5f91<\/a><\/h3>\n<p>\u5728C\/C++\u914d\u7f6e\u87a2\u5e55\u4e0a\uff0c\u5411\u4e0b\u6efe\u52d5\u4e26\u5c55\u958b <strong>\u9ad8\u968e\u8a2d\u5b9a<\/strong> \uff0c\u4e26\u78ba\u4fdd<strong>Mac\u6846\u67b6\u8def\u5f91<\/strong>\u6307\u5411\u7cfb\u7d71\u982d\u6a94\u6848\u3002 \u4f8b\u5982\uff1a<code>\/Library\/Developer\/CommandLineTools\/SDKs\/MacOSX.sdk\/System\/Library\/Frameworks<\/code><\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_troubleshooting\">\u6545\u969c\u6392\u9664<\/a><\/h2>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_compiler-and-linking-errors\">\u7de8\u8b6f\u5668\u548c\u9023\u7d50\u932f\u8aa4<\/a><\/h3>\n<p>\u7576\u60a8\u958b\u59cb\u69cb\u5efa\u6216\u958b\u59cb\u9664\u932f\u6642\uff0c<code>helloworld.cpp<\/code>\u4e0d\u662f\u6d3b\u52d5\u6a94\u6848\u6642\uff0c\u6700\u5e38\u898b\u7684\u932f\u8aa4\u539f\u56e0\uff08\u5982 <code>undefined _main<\/code>\uff0c\u6216 <code>attempting to link with file built for unknown-unsupported file format<\/code>\u7b49\uff09\u5c31\u6703\u767c\u751f\u3002 \u9019\u662f\u56e0\u70ba\u7de8\u8b6f\u5668\u6b63\u5728\u5617\u8a66\u7de8\u8b6f\u4e0d\u662f\u6e90\u7a0b\u5f0f\u7684\u6771\u897f\uff0c\u6bd4\u5982\u4f60\u7684 <code>launch.json<\/code>\u3001<code>tasks.json<\/code>\u6216 <code>c_cpp_properties.json<\/code>\u6a94\u6848\u3002<\/p>\n<p>\u5982\u679c\u60a8\u770b\u5230\u63d0\u53ca\u201cC++11\u64f4\u5145\u5957\u4ef6\u201d\u7684\u69cb\u5efa\u932f\u8aa4\uff0c\u60a8\u53ef\u80fd\u6c92\u6709\u66f4\u65b0\u60a8\u7684 <code>tasks.json<\/code>\u69cb\u5efa\u4efb\u52d9\u4ee5\u4f7f\u7528clang++\u5f15\u6578 <code>--std=c++17<\/code>\u3002 \u9810\u8a2d\u60c5\u6cc1\u4e0b\uff0cclang++\u4f7f\u7528C++98\u6a19\u6e96\uff0c\u8a72\u6a19\u6e96\u4e0d\u652f\u63f4 <code>helloworld.cpp<\/code>\u4e2d\u4f7f\u7528\u7684\u521d\u59cb\u5316\u3002\u8acb\u78ba\u4fdd\u5c07 <code>tasks.json<\/code>\u6a94\u6848\u7684\u5168\u90e8\u5167\u5bb9\u66ff\u63db\u70ba\u201c<a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_run-helloworldcpp\">\u57f7\u884chelloworld.cpp\u201d<\/a>\u90e8\u5206\u4e2d\u63d0\u4f9b\u7684\u7a0b\u5f0f\u584a\u3002<\/p>\n<h3><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_terminal-wont-launch-for-input\">\u7d42\u7aef\u7121\u6cd5\u555f\u52d5\u8f38\u5165<\/a><\/h3>\n<p>On macOS Catalina and onwards, you might have the issue where you are unable to enter input, even after setting<strong> <\/strong><code>&quot;externalConsole&quot;: true<\/code>. A terminal window opens, but it does not actually allow you to type any input.<\/p>\n<p>\u8a72\u554f\u984c\u76ee\u524d\u6b63\u5728\u8ddf\u8e64<a href=\"https:\/\/github.com\/microsoft\/vscode-cpptools\/issues\/5079\">#5079<\/a>\u3002<\/p>\n<p>\u89e3\u6c7a\u8fa6\u6cd5\u662f\u8b93VS Code\u555f\u52d5\u4e00\u6b21\u7d42\u7aef\u3002 \u60a8\u53ef\u4ee5\u900f\u904e\u5728 <code>tasks.json<\/code>\u4e2d\u65b0\u589e\u548c\u57f7\u884c\u6b64\u4efb\u52d9\u4f86\u505a\u5230\u9019\u4e00\u9ede\uff1a<\/p>\n<pre><code>{\n\"label\": \"Open Terminal\",\n\"type\": \"shell\",\n\"command\": \"osascript -e 'tell application \\\"Terminal\\\"\\ndo script \\\"echo hello\\\"\\nend tell'\",\n\"problemMatcher\": []\n}<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u201c <strong>\u7d42\u7aef<\/strong> \u201d&gt;\u201c <strong>\u57f7\u884c\u4efb\u52d9\u201d<\/strong> \u57f7\u884c\u6b64\u7279\u5b9a\u4efb\u52d9 <strong>......<\/strong> \u7136\u5f8c\u9078\u64c7\u201c <strong>\u958b\u555f\u7d42\u7aef<\/strong> \u201d\u3002<\/p>\n<p>\u4e00\u65e6\u60a8\u63a5\u53d7\u8a31\u53ef\u6b0a\u8acb\u6c42\uff0c\u9664\u932f\u6642\u61c9\u8a72\u6703\u51fa\u73fe\u5916\u90e8\u63a7\u5236\u6aaf\u3002<\/p>\n<h2><a href=\"https:\/\/code.visualstudio.com\/docs\/cpp\/config-clang-mac#_next-steps\">\u4e0b\u4e00\u6b65<\/a><\/h2>\n<ul>\n<li>\u63a2\u7d22<a href=\"https:\/\/code.visualstudio.com\/docs\/editor\/codebasics\">VS\u7a0b\u5f0f\u4f7f\u7528\u8005\u6307\u5357<\/a>\u3002<\/li>\n<li>\u6aa2\u8996<a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/cpp\">C++\u64f4\u5145\u5957\u4ef6<\/a>\u7684<a href=\"https:\/\/code.visualstudio.com\/docs\/languages\/cpp\">\u6982\u8ff0<\/a><\/li>\n<li>\u5efa\u7acb\u4e00\u500b\u65b0\u7684\u5de5\u4f5c\u5340\uff0c\u5c07\u60a8\u7684.json\u6a94\u6848\u8907\u88fd\u5230\u5176\u4e2d\uff0c\u8abf\u6574\u65b0\u5de5\u4f5c\u5340\u8def\u5f91\u3001\u7a0b\u5f0f\u540d\u7a31\u7b49\u7684\u5fc5\u8981\u8a2d\u5b9a\uff0c\u7136\u5f8c\u958b\u59cb\u7de8\u78bc\uff01<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Visual Studio Code\u4e2d\u4f7f\u7528Clang \u5728\u672c\u6559\u7a0b\u4e2d\uff0c\u60a8\u5c07\u5728macOS\u4e0a\u914d\u7f6eVisual Stu&#8230; &raquo; <a class=\"read-more-link\" href=\"https:\/\/vm1.go2see.me\/?p=629\">\u95b1\u8b80\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-629","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=629"}],"version-history":[{"count":1,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/629\/revisions"}],"predecessor-version":[{"id":630,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=\/wp\/v2\/posts\/629\/revisions\/630"}],"wp:attachment":[{"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vm1.go2see.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}