Study: Software(SW)/SW: Error Bug Fix

[Error fix] 'incremental compilation: could not create session directory lock file: No locks available' 오류 해결(feat. Rust Cargo profiles)

DrawingProcess 2023. 1. 5. 17:46
반응형

# 문제 상황

Rust를 초기에 세팅하는 과정에서 새로운 패키지(hello_rust)를 만들고 'cargo build' 를 통해 빌드하려다보니 다음과 같은 오류가 발생하였다.

# 해결 방안

방법 1: Cargo.toml 파일에 추가(권장)

[profile.dev]
incremental = false

방법 2: 방법 1로 해결하는 것이 Rust 가 권장(?)하는 세팅이다.

incremental compilation 오류의 경우 경로문제인 듯하다. 따라서 경로설정을 해주고 build를 하면 성공하게 된다.

// 현재 경로에서 빌드
$ CARGO_INCREMENTAL=0 cargo build
// /tmp 경로에서 빌드
$ CARGO_TARGET_DIR=/tmp cargo build

이 경우에 실행할 때에 있어서도 붙여주어야 한다.

// target/ 경로에서 빌드
$ CARGO_INCREMENTAL=0 cargo run
// /tmp 경로에서 빌드
$ CARGO_TARGET_DIR=/tmp cargo run

따라서 불편함을 방지하고자 ~/.bashrc 파일에 변수를 지정해주면 편하게 빌드 및 실행을 할 수 있다.

$ nano ~/.bashrc
...
expert CARGO_INCREMENTAL=0
...
$ source ~/.bashrc
$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/hello_rust`
Hello, world!

# 참고

반응형