๐ก ๋ณธ ๋ฌธ์๋ 'M1 ๋งฅ๋ถ์์ VSCODE C++ ๊ฐ๋ฐํ๊ฒฝ ์ค์ '์ ๋ํด ์ ๋ฆฌํด๋์ ๊ธ์ ๋๋ค.
VSCode๋ก ๊ฐ๋ฐํ๊ฒฝ์ ์ธํ ํ๋ค๋ณด๋ฉด tasks.json, launch.json ๋ฑ ์ด๋ป๊ฒ ํ ์ง ํท๊ฐ๋ฆด๋๊ฐ ๋ง์ต๋๋ค. ์ด๋ ์ผ๋ถ OS dependencyํ ์ค์ ๋ ๋ง๊ธฐ์ ์ผ๋จ ์ ๊ฐ๋ฐํ๊ฒฝ์ธ M1 Mac์์ ๋๋ฒ๊น ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ ๋ฆฌํด ๋์์ผ๋ ์ฐธ๊ณ ํ์๊ธฐ ๋ฐ๋๋๋ค.
1. ๊ฐ๋ฐ ํ๊ฒฝ ์ธํ
1.1 VSCODE ๋ค์ด๋ก๋
mac OS ํ๊ฒฝ ๋ฐ M1 ์ด๋ผ๋ฉด Apple Silicon ๋ฒ์ ๋ค์ด๋ก๋ํฉ๋๋ค.
- ์ง์ ๋ค์ด๋ก๋: https://code.visualstudio.com/#alt-downloads
- brew๋ฅผ ์ด์ฉํ ์ค์น: https://polarcompass.tistory.com/140?category=514165
1.2 VSCode Extension ์ค์น
1.2.1 C++ Extension ์ค์น
1.2.2 CodeLLDB ๋๋ฒ๊น Extension ์ค์น
1.3 Clang ์ค์น ๋ฐ ํ์ธ
ํฐ๋ฏธ๋ ์ฐฝ์ ์๋ ๋ด์ฉ์ ์ ๋ ฅํ์ฌ clang์ด M1์ ์ค์น๋์ด ์๋ ํ์ธํฉ๋๋ค.
$ clang --version
๋ง์ฝ, ์ค์น๋์ด ์์ง ์์ผ๋ฉด ์๋ ์ฝ๋๋ฅผ ์ ๋ ฅํ๊ฑฐ๋ xcode๋ฅผ ์ค์นํ๋ฉด ํด๊ฒฐ๋ฉ๋๋ค.
$ xcode-select --install
2. ๋๋ฒ๊น ํ๊ฒฝ ์ธํ
ํด๋ ์ด๋ฆ์ ๋ณธ์ธ์ด ์ํ๋ ์ด๋ฆ์ผ๋ก ์์ฑํ๊ณ , ๋ด๋ถ์ ๊ธฐ๋ณธ cpp ํ์ผ ์ธ ์์ผ๋ก ๋ค์ ์ธ๊ฐ์ ํ์ผ์ ์ ํ ํ๋ ๊ฒ์ ๋ชฉํ๋ก ํ๋ค.
- tasks.json - complier build settings
- launch.json - debugger settings
- c_cpp_properties.json - complier path and IntelliSense settings
์ดํ์ ์๋ก์ด ํด๋๋ฅผ ์์ฑํ๋ฉด ์์ ์ธ๊ฐ ํ์ผ์ ๋ณต์ฌํด์ ๋ถ์ฌ๋ฃ์ผ๋ฉด ๋์ผํ ์ธํ ๊ฐ์ผ๋ก ๊ฐ๋ฐ์ด ๊ฐ๋ฅํ๋ค.
2.1 cpp ํ์ผ ์์ฑ
์ผ์ชฝ ๋ฐ์ ํ๋จ ๊ทธ๋ฆผ์ ์์น์ ์์ด์ฝ์ ํด๋ฆญํ์ฌ test.cpp๋ผ๋ ์ด๋ฆ์ผ ์๋ก์ด ํ์ผ์ ์์ฑํฉ๋๋ค.
์ดํ ํ์ผ ๋ด๋ถ์ ์๋ ์ฝ๋๋ฅผ ๋ณต๋ถํ ํ Ctrl + S ๋ก ์ ์ฅํฉ๋๋ค.
#include <iostream>
using namespace std;
int main()
{
cout << "HelloWorld\n";
}
2.2 Build test.cpp: tasks.json ํ์ผ ์์ฑ
test.cpp๋ฅผ build ํ๊ธฐ ์ํ์ฌ tasks.json ํ์ผ์ ์์ฑํด์ผ ํฉ๋๋ค. ์ด๋ฅผ ์ํด VSCode ๋ด์ ์๋จ๋ฐ ๋ฉ์ธ ๋ฉ๋ด์์ Terminal(ํฐ๋ฏธ๋) > Configure Default Build Task(๊ธฐ๋ณธ ๋น๋ ์์ ๊ตฌ์ฑ...) ๋ก ๋ค์ด๊ฐ๋๋ค. ์ดํ C/C++ clang++ build active file ์ ํํฉ๋๋ค.
tasks.json ๊ฐ ์์ฑ๋๋ฉด ์๋ ์ฝ๋๋ฅผ ๋ณต๋ถํฉ๋๋ค.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
// ํ์ฌ VSCode ์ ํ๋ก์ ํธ ํด๋๊ฐ ${workspaceFolder}์ด๋ฉฐ ์ด๋ฅผ ๊ธฐ์ค์ผ๋ก ์คํ ํ์ผ์ ์์น๋ฅผ ๊ธฐ์ฌ
"${workspaceFolder}/dp/RGBDistance.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
์ดํ test.cpp ํ์ผ๋ก ๋์์์ Cmd+Shift+B ๋ก ํ์ผ์ build ํฉ๋๋ค.
2.3 Execute & Debug test.cpp: launch.json ํ์ผ ์์ฑ
๋ค์์ launch.json ์ ๋ง๋ค์ด์ค๋ค. Fn + F5 ๋๋ฌ debug๋ฅผ ์คํํด์ค๋๋ค. ์ด๋ฅผ ์ํด VSCode ๋ด์ ์๋จ๋ฐ ๋ฉ์ธ ๋ฉ๋ด์์ Run > Add Configuration... ์ ์ ํํ ํ C++ (GDB/LLDB) ์ ํํฉ๋๋ค. ๊ทธ ๋ค์ ๋ค์๊ณผ ๊ฐ์ ์ ํ์ง๋ฅผ ๋ณด๊ฒ ๋ฉ๋๋ค.
๊ทธ ํ launch.json ํ์ผ์ด ์์ฑ ๋ ํ ์๋์ ๊ฐ์ ์ฝ๋ ๋ณต๋ถํฉ๋๋ค.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
โป ์ฃผ์์
tasks.json ์ label ๋ถ๋ถ๊ณผ launch.json์ preLaunchTask ๋ถ๋ถ ์ด๋ฆ์ด ๊ฐ์์ผ ํฉ๋๋ค. launch.json์ ์ฝ๋ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ, launch.json ๋ด๋ถ์ preLaunchTask์ ๊ฐ์ tasks.json ๋ด๋ถ์ label์ ์ฐพ์์ ์คํํ๋ ๊ฒ์ผ๋ก ๋ณด์ ๋๋ค.
tasks.json
"label": "clang++ build active file",
launch.json
"preLaunchTask": "clang++ build active file"
ํ๊ธ๋ก ๋์ด์์ ๊ฒฝ์ฐ์ ๋๋๋ก ์์ด๋ก ๋ฐ๊ฟ ์ฃผ๋๋ก ํฉ๋๋ค.
2.4 C/C++ configuration ์ธํ
์ด์ c_cpp_properties.json ํ์ผ ์ธํ ํ๊ธฐ ์ํด Ctrl+Shift+P ๋จ์ถํค๋ก Command Palette ์ด์ด์ค๋๋ค.
์ดํ C/C++:Edit Configurations (UI) ๋ก UI ํํ๋ก ์ธํ ํ๊ฑฐ๋ C/C++:Edit Configurations (JSON) ์ผ๋ก ์๋ ์ฝ๋๋ฅผ ๋ณต๋ถํฉ๋๋ค.
{
"configurations": [
{
"name": "Mac",
"includePath": ["${workspaceFolder}/**"],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
3. ๋์ ๋๋ฒ๊น ์ธํ
3.1 tasks.json
ํน์ ์์น์์ ํ์ผ์ ์คํ์์ผฐ์ ๋, Debug/ ํด๋ ๋ด๋ถ์ ๋ฐ์ด๋๋ฆฌ ์คํํ์ผ ๋ฐ *.dSYM/ ํด๋๋ฅผ ๋ฃ๋๋ก ๊ตฌ์ฑํ์์ต๋๋ค.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"Debug/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- "${workspaceFolder}/dp/RGBDistance.cpp" -> "${file}"
- "Debug/${fileBasenameNoExtension}" -> "Debug/${fileBasenameNoExtension}"
- ์ฐธ๊ณ : https://code.visualstudio.com/docs/editor/variables-reference
3.2 launch.json
Debug/ ํด๋ ๋ด๋ถ์ ๋ฐ์ด๋๋ฆฌ ์คํํ์ผ์ ์ฐพ์์ ์คํํ๋๋ก ๊ตฌ์ฑํ์์ต๋๋ค.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "clang++ - Build and debug active file",
"type": "lldb",
"request": "launch",
"program": "Debug/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang++ build active file"
}
]
}
์ฐธ๊ณ
- [VSCode] Using Clang in Visual Studio Code: https://code.visualstudio.com/docs/cpp/config-clang-mac
- [VSCode] Variables Reference(Predefined): https://code.visualstudio.com/docs/editor/variables-reference
- [Blog] ๋งฅ๋ถ M1 VSCODE C++ ์ค์ ํ๊ฒฝ ์ค์ ๊ฐ๋ฐํ๊ฒฝ ์ธํ AppleSilicon: https://polarcompass.tistory.com/12
'Study: DeveloperTools(DevTool) > DevTool: IDE' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[IDE] VSCode Springboot ๊ฐ๋ฐํ๊ฒฝ ์ค์ (MacOS M1) (0) | 2023.01.21 |
---|---|
[IDE] VSCode React + .Net ๊ฐ๋ฐํ๊ฒฝ ์ค์ (MacOS M1) (0) | 2023.01.16 |
[IDE] VSCode C++ ๋๋ฒ๊น ํ๊ฒฝ ์ธํ (task.json, launch.json): GCC on Linux (feat. ๋ชจ๋ ์ค๋จ์ ์์ ๋ฉ์ถ๋๋ก) (0) | 2022.07.08 |
[IDE] VSCode ์ ์ฉํ Extension ์ ๋ฆฌ (0) | 2022.06.09 |
[IDE] Visual Studio ์ค๋ ๊ณ ๊ธ ์ ์ฅ ์ต์ (0) | 2020.09.08 |