jguhlin / minimap2-rs

Rust bindings to minimap2 library
Other
60 stars 13 forks source link

c_int and c_char type not found. #1

Closed dwpeng closed 1 year ago

dwpeng commented 1 year ago

while compling minimap-sys, I got a error.

Error

Compiling minimap2-sys v0.1.5
   Compiling minimap2 v0.1.5
error[E0412]: cannot find type `c_char` in module `std::ffi`
   --> /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/minimap2-0.1.5/src/lib.rs:619:63
    |
619 | ...                   let mut cs_string: *mut std::ffi::c_char = std::ptr::null_mut();
    |                                                         ^^^^^^ not found in `std::ffi`
    |
help: consider importing one of these items
    |
1   | use core::ffi::c_char;
    |
1   | use libc::c_char;
    |
1   | use std::os::raw::c_char;
    |
help: if you import `c_char`, refer to it directly
    |
619 -                             let mut cs_string: *mut std::ffi::c_char = std::ptr::null_mut();
619 +                             let mut cs_string: *mut c_char = std::ptr::null_mut();
    |

error[E0412]: cannot find type `c_int` in module `std::ffi`
   --> /root/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/minimap2-0.1.5/src/lib.rs:620:60
    |
620 | ...                   let mut m_cs_string: std::ffi::c_int = 0i32;
    |                                                      ^^^^^ not found in `std::ffi`
    |
help: consider importing one of these items
    |
1   | use core::ffi::c_int;
    |
1   | use libc::c_int;
    |
1   | use std::os::raw::c_int;
    |
help: if you import `c_int`, refer to it directly
    |
620 -                             let mut m_cs_string: std::ffi::c_int = 0i32;
620 +                             let mut m_cs_string: c_int = 0i32;
    |

For more information about this error, try `rustc --explain E0412`.
error: could not compile `minimap2` due to 2 previous errors
// main.rs
use minimap2::*;
fn main(){
  let mut aligner = Aligner {
          threads: 8,
          ..map10k()
      }
      .with_cigar()
      .with_index("test.fa", Some("ret.sam"))
      .expect("Unable to build index");

      let seq: Vec<u8> = b"ACTGACTCACATCGACTACGACTACTAGACACTAGACTATCGACTACTGACATCGA";
      let alignment = aligner
          .map(&seq, false, false, None, None)
          .expect("Unable to align");

  }
}
// Cargo.toml
[package]
name = "roa"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bio = "1.0.0"
minimap2 = "0.1.5"
uuid = { version = "1.2.1", features = ["v4", "fast-rng", "macro-diagnostics"] }

FIX IT

I chenged std::ffi::* to libc::*, and I complied successfully.

- let mut cs_string: *mut std::ffi::c_char = std::ptr::null_mut();
+  let mut cs_string: *mut libc::c_char = std::ptr::null_mut();
...
jguhlin commented 1 year ago

Thanks! I'll switch this in the code base as it will make it more portable. Just curious, what version of rustc do you have? I think the std:ffi::c_char is just in the newest stable version, so that likely caused the problem.

dwpeng commented 1 year ago

Thanks! I'll switch this in the code base as it will make it more portable. Just curious, what version of rustc do you have? I think the std:ffi::c_char is just in the newest stable version, so that likely caused the problem.

My rustc version is rustc 1.63.0 (4b91a6ea7 2022-08-08)

jguhlin commented 1 year ago

Ok, thanks. Looks like c_char was added in 1.64. Cool.

Let me know if you have any other trouble with the library or any missing features you want! I'll push out a new version to crates.io as well.