rust 개발환경 준비 - Hello World!

Sungyong
5 min readJan 9, 2024

--

대세가 된 rust 를 시작한다.

무엇이든 시작은 Hello World! 부터!

실제 Hello World! 까지도 마음 먹은 대로 쉽게 된 적은 없던 것 같다.

IDE는 VSCode로 한다.

최소 필요요소는 rustc, cargo.

VS Extension으로 rust 를 설치한다.

이제 scoop package manager 로 rust 설치

PS C:\Workspace\working\rust> scoop install rust
Updating Scoop...
Updating 'extras' bucket...
Installing 'rust' (1.75.0) [64bit] from main bucket
rust-1.75.0-x86_64-pc-windows-msvc.msi (211.8 MB) [==================================================] 100%
Checking hash of rust-1.75.0-x86_64-pc-windows-msvc.msi ... ok.
Extracting rust-1.75.0-x86_64-pc-windows-msvc.msi ... done.
Linking ~\scoop\apps\rust\current => ~\scoop\apps\rust\1.75.0
Creating shim for 'rustc'.
Creating shim for 'cargo'.
'rust' (1.75.0) was installed successfully!
-----
According to https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows
https://visualstudio.microsoft.com/visual-cpp-build-tools/
When installing build tools, these two components should be selected:
- MSVC - VS C++ x64/x86 build tools
- Windows SDK

rustc와 cargo가 설치되었다.

PS C:\Workspace\working\rust> rustc --version
rustc 1.75.0 (82e1608df 2023-12-21)
PS C:\Workspace\working\rust> cargo --version
cargo 1.75.0 (1d8b05cdd 2023-11-20)

하지만 build를 하기 위해서는 MSVC와 Windows SDK가 필요하다고 한다.

설치하지 않고 그냥 해 보면,

PS C:\Workspace\working\rust> rustc .\Example.rs
error: linker `link.exe` not found
= note: program not found

note: please ensure that Visual Studio 2017 or later, or Build Tools for Visual Studio were installed with the
Visual C++ option.

note: VS Code is a different product, and is not sufficient.

error: aborting due to previous error

이렇게 MSVC를 설치하라고 한다.

그래서 Visual Studio Community 2022 버전 설치하고, C++ 항목만 켰다.

그리고 나서 build

PS C:\Workspace\working\rust\learning_rust> cargo build
Compiling learning_rust v0.1.0 (C:\Workspace\working\rust\learning_rust)
Finished dev [unoptimized + debuginfo] target(s) in 2.49s

Hello World도 실행

PS C:\Workspace\working\rust\learning_rust> cargo run 
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target\debug\learning_rust.exe`
Hello, world!

언어 자체만 연습할 때는 굳이 IDE까지 환경 설정에 시간을 쏟기 보다는 Web Playground 하는 것이 더 나을 수도 있다.

https://play.rust-lang.org

--

--

No responses yet