๋‚ด ์ธ์ƒ์—์„œ ๋ฏฟ์„ ๊ฑด ์˜ค์ง ๋‚˜ ์ž์‹ ๋ฟ!

The only one you can truly trust is yourself.

๊ฒŒ์ž„ ํ”„๋กœ๊ทธ๋ž˜๋ฐ/Rust ํ”„๋กœ๊ทธ๋ž˜๋ฐ

Rust Programming (๋Ÿฌ์ŠคํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ) #4. VS Code ์„ค์ •

๐ŸŽฎinspirer9 2020. 6. 15. 01:53
728x90
๋ฐ˜์‘ํ˜•

์œ ๋‹ˆํ‹ฐ์™€ ์–ธ๋ฆฌ์–ผ ์—”์ง„ ๋•Œ๋ฌธ์— ๋น„์ฃผ์–ผ ์ŠคํŠœ๋””์˜ค 2017๋ฅผ ์‚ฌ์šฉํ–ˆ๊ณ , ๊ทธ๋ž˜์„œ Visual Rust ์‚ฌ์šฉํ•ด๋ณด๋ ค๋‹ค๊ฐ€ VS Code๊ฐ€ ๋” ์“ฐ๊ธฐ ํŽธํ•˜๋‹ค๋Š” ์ด์•ผ๊ธฐ๋“ค์ด ์žˆ์–ด์„œ VS Code๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๊ธฐ๋กœ ํ–ˆ๋‹ค.

VS Code ์„ค์น˜ - https://code.visualstudio.com/

Visual Studio Code - Code Editing. Redefined

Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications.  Visual Studio Code is free and available on your favorite platform - Linux, macOS, and Windows.

code.visualstudio.com

Visual C++ Build Tool๋„ ์„ค์น˜ - https://visualstudio.microsoft.com/ko/visual-cpp-build-tools/

Microsoft C++ Build Tools - Visual Studio

Microsoft C++ Build Tools๋Š” Visual Studio ์—†์ด ์Šคํฌ๋ฆฝํŠธ ๊ฐ€๋Šฅํ•œ ๋…๋ฆฝ ์‹คํ–‰ํ˜• ์„ค์น˜ ๊ด€๋ฆฌ์ž๋ฅผ ํ†ตํ•ด MSVC ๋„๊ตฌ ์ง‘ํ•ฉ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋ช…๋ น์ค„์—์„œ Windows๋ฅผ ๋Œ€์ƒ์œผ๋กœ ํ•˜๋Š” C++ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๋ฐ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋นŒ๋“œ๏ฟฝ

visualstudio.microsoft.com

VS Code๋ฅผ ์‹คํ–‰ํ•˜๊ณ , Extensions์—์„œ C/C++๊ณผ Rust๋ฅผ ์„ค์น˜ํ•œ๋‹ค.

 

 

์„ค์น˜ ๋, ์ด์ œ VS Code๋กœ ๋Ÿฌ์ŠคํŠธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ํ•˜๋ ค๋ฉด,
Cargo๋ผ๋Š” ๋Ÿฌ์ŠคํŠธ ๋นŒ๋“œ ์‹œ์Šคํ…œ์„ ์ด์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.

๋Ÿฌ์ŠคํŠธ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ

๋Ÿฌ์ŠคํŠธ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ๋Š” ์ฑ…์„ ๋”ฐ๋ผ ํ•˜๋ฉด ๋œ๋‹ค. - https://rinthel.github.io/rust-lang-book-ko/ch01-03-hello-cargo.html

์•„๋ž˜๋Š” ํ—ฌ๋กœ_์นด๊ณ ๋ผ๋Š” ์ƒˆ ํ”„๋กœ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ช…๋ น์–ด.

--bin ์˜ต์…˜์€ ์‹คํ–‰ํŒŒ์ผ๋กœ ๋งŒ๋“ค๋ผ๋Š” ์˜๋ฏธ. ์ด ์˜ต์…˜ ์•ˆํ•˜๋ฉด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์–ด ์ค€๋‹ค๊ณ  ํ•œ๋‹ค.

cargo new hello_cargo --bin

๊ทธ๋Ÿฌ๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํด๋” 2๊ฐœ์™€ ํŒŒ์ผ 3๊ฐœ๊ฐ€ ๋งŒ๋“ค์–ด ์ง„๋‹ค.

hello_cargo
โ”œ .gitignore
โ”œ Cargo.toml
โ”” src 
  โ”” main.rs

 

 

Cargo.toml ํŒŒ์ผ์€ ์นด๊ณ ์˜ ํ™˜๊ฒฝ ์„ค์ • ํŒŒ์ผ.

main.rs ํŒŒ์ผ์€ ํ—ฌ๋กœ ์›”๋“œ์™€ ๋˜‘๊ฐ™์€ ๋ฉ”์ธ ์†Œ์Šค ํŒŒ์ผ.

.gitignore ํŒŒ์ผ์€ Git์œผ๋กœ ํ”„๋กœ์ ํŠธ ๊ด€๋ฆฌํ•  ๋•Œ, ๊ด€๋ฆฌํ•  ํ•„์š”๊ฐ€ ์—†๋Š” ํŒŒ์ผ๋“ค์„ ์ •์˜ํ•˜๋Š” ํŒŒ์ผ.

.gitignore ํŒŒ์ผ ์„ค์ •๋ฒ•

Git ์œผ๋กœ ํ”„๋กœ์ ํŠธ๋ฅผ ๊ด€๋ฆฌํ•œ๋‹ค๊ณ  ํ–ˆ์„ ๋•Œ, ๊ทธ ํ”„๋กœ์ ํŠธ์•ˆ์˜ ํŠน์ •ํŒŒ์ผ๋“ค์€ Git ์œผ๋กœ ๊ด€๋ฆฌํ•  ํ•„์š”์—†๋Š” ๊ฒƒ๋“ค๋„ ์žˆ๋‹ค. ์ž๋™์œผ๋กœ ์ƒ์„ฑ๋˜๋Š” ๋กœ๊ทธํŒŒ์ผ๋“ค, ๋นŒ๋“œํ•  ๋•Œ ์ƒ๊ธฐ๋Š” ์ปดํŒŒ์ผ๋œ ํŒŒ์ผ๋“ค(์ž๋ฐ”ํ”„๋กœ์ ๏ฟฝ

emflant.tistory.com

VS Code๋กœ hello_cargo ์—ด๊ธฐ

hello_cargo ํด๋”๋ฅผ ์—ด๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ํ”„๋กœ์ ํŠธ ํ˜•ํƒœ๋กœ ๋กœ๋”ฉํ•ด์ค€๋‹ค.

 

 

F5 ๋ˆŒ๋Ÿฌ์„œ ์‹คํ–‰ํ•˜๋ฉด, Rust ๊ด€๋ จ๋œ ์„ค์น˜๊ฐ€ ๋ช‡๊ฐœ ๋” ํ•„์š”ํ•˜๋‹ค๊ณ  ๋‚˜์˜จ๋‹ค.

Yes ๋ˆŒ๋Ÿฌ์„œ rust-analysis๋ž‘ ๊ทธ์™ธ ๊ธฐํƒ€ ์ž๋™์œผ๋กœ ์„ค์น˜ ํ•ด์ค€๋‹ค.

๊ทธ๋ฆฌ๊ณ  launch.json ํŒŒ์ผ๊นŒ์ง€ ์—ด์–ด์ค€๋‹ค.

 

 

launch.json์„ ์–ด๋–ป๊ฒŒ ์ˆ˜์ •ํ•ด์•ผ๋˜๋Š”๊ฑด๊ฐ€?

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) ์‹œ์ž‘",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/helloworld.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false
        }
    ]
}

ํ”„๋กœ๊ทธ๋žจ ์ด๋ฆ„ ์ž…๋ ฅ(์˜ˆ: ...) ๋ถ€๋ถ„์— ํŒŒ์ผ๋ช…์„ helloworld.exe๋กœ ํ–ˆ๋Š”๋ฐ ํŒŒ์ผ์„ ์ฐพ์ง€ ๋ชปํ•œ๋‹ค๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋‚˜์™”๋‹ค.

๊ทธ๋ž˜์„œ -> ํ„ฐ๋ฏธ๋„ -> ๋Ÿฐ ๋นŒ๋“œ ํƒœ์Šคํฌ.

 

 

๋นŒ๋“œ๋ฅผ ํ•˜๋ฉด ์ด๋ ‡๊ฒŒ target/debug/ ํด๋” ์•ˆ์— hello_cargo๋ผ๋Š” ์‹คํ–‰ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค.

์นด๊ณ  ํŒจํ‚ค์ง€์˜ ์ด๋ฆ„์œผ๋กœ ์‹คํ–‰ํŒŒ์ผ์ด ๋งŒ๋“ค์–ด์ง„๋‹ค. ใ…‹

 

 

helloworld.exe๋ฅผ hello_cargo.exe๋กœ ๋ณ€๊ฒฝํ•˜๊ณ ,

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) ์‹œ์ž‘",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/hello_cargo.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": false
        }
    ]
}

F5๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด. ๋””๋ฒ„๊ทธ ์ฝ˜์†”์— ์„ž์—ฌ์„œ ๊ฒฐ๊ณผ๊ฐ€ ๋‚˜์˜จ๋‹ค.

 

 

๊ทธ๋Ÿด ๋•, Run Without Debugging์„ ํ•˜๋ฉด,

 

 

์•„๋ž˜์ฒ˜๋Ÿผ ๊ฒฐ๊ณผ๋งŒ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

CTRL+F5๋ฅผ ๊ธฐ์–ตํ•˜์ž!

 

 

๊ทธ๋ฆฌ๊ณ  ์œ ์ € ์„ธํŒ…์—์„œ Allow Breakpoints Everywhere ์„ค์ •ํ•ด์ค€๋‹ค.

์›น์„œํ•‘ํ•ด๋ณด๋‹ˆ๊นŒ ๋Œ€๋ถ€๋ถ„ ์ €๊ฒƒ๋„ ํ•˜๋”๋ผ๊ณ . ๊ฑ ๋”ฐ๋ผํ•ด์•ผ์ง€.

 

 

๋.

728x90
๋ฐ˜์‘ํ˜•