Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

라이브러리 생성

라이브러리를 만든 다음, 이를 다른 크레이트와 어떻게 연결하는지 살펴봅시다.

rary.rs에서:

pub fn public_function() {
    println!(rary의 `public_function()` 호출됨);
}

fn private_function() {
    println!(rary의 `private_function()` 호출됨);
}

pub fn indirect_access() {
    print!(rary의 `indirect_access()` 호출됨, 결과는\n> ");

    private_function();
}
$ rustc --crate-type=lib rary.rs
$ ls lib*
library.rlib

라이브러리에는 “lib” 접두사가 붙으며, 기본적으로 크레이트 파일의 이름을 따서 명명되지만, 이 기본 이름은 rustc--crate-name 옵션을 전달하거나 crate_name 속성을 사용하여 재정의할 수 있습니다.