3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

build.rsでLIBやPATH環境変数を設定せずにcargo runする

Last updated at Posted at 2017-09-13

背景

Go言語でlibhoge.aを作り、hoge.dll、hoge.libを作って、これらをRustから使う方法を試した。

これらは、.libファイルは環境変数LIBにパスを追加、.dllは環境変数PATHにパスをそれぞれ追加することで、利用可能だが、git cloneしてcargo run一発で動かしたい。

build.rs

use std::env;
use std::fs;
use std::path::Path;

fn main() {
    let out_dir = env::var("OUT_DIR").unwrap();
    let dest_lib_path = Path::new(&out_dir).join("../../../deps").join(
        "hoge.lib",
    );
    let dest_dll_path = Path::new(&out_dir).join("../../..").join("hoge.dll");
    let _ = fs::copy("./vendor/hoge.dll", dest_dll_path);
    let _ = fs::copy("./vendor/hoge.lib", dest_lib_path);
}

libファイルはOUT_DIRにコピーして、OUT_DIRをライブラリパスとしてしてしても
対応できるが、この方法の方が、手間いらず。

実際に動かした様子

mruby-webcam

関連

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?