return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>Using an .a library to compile with "rustc" in Rust - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Using an .a library to compile with "rustc" in Rust - Stack Overflow

programmeradmin3浏览0评论

Is there a way to compile a crate Rust and its dependencies into an .a (or .rlib) file that can then be used when compiling another .rs file with "rustc" ?

For example, here is the Cargo.toml file used to create a static library enabling all postgres functions to be used (without going through cargo):

[lib]
name = "my_postgres_lib"
crate-type = ["staticlib"]

[dependencies]
postgres = "0.19"

Here are the contents of the src/lib.rs file:

extern crate postgres;

pub use postgres::*;

And here is the main.rs file to be compiled without going through cargo (with ‘rustc main.rs -L ../my_postgres_lib/target/release -l my_postgres_lib’):

extern crate my_postgres_lib;
use my_postgres_lib::{Client, NoTls};

fn main() {
    match Client::connect("host=localhost user=postgres", NoTls) {
        Ok(mut client) => {
            println!("Success");
        }
        Err(e) => {
            eprintln!("Error : {}", e);
        }
    }
}

Unfortunately, the rustc command given above always gives me this kind of response:

error[E0463]: can't find crate for `postgres` which `my_postgres_lib` depends on
 --> main.rs:8:1
  |
8 | extern crate my_postgres_lib;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0463`.
发布评论

评论列表(0)

  1. 暂无评论