c_import

This is a small crate providing a cimport macro (also a cppimport macro), which can be used to import C headers into your program. You need bindgen to be installed in your system.

Usage

```toml

Cargo.toml

[depenedencies] c_import = "0.1" ```

```rust // src/main.rs use cimport::cimport;

c_import!();

fn main() { let version = unsafe { cairo_version() }; println!("{}", version); } ```

rust // build.rs fn main() { println!("cargo:rustc-link-lib=cairo"); }

Using non-system headers is also possible via enclosing the header path with quotation marks: ```rust use cimport::cimport; cimport!("src/myheader.h");

fn main() { let version = unsafe { cairo_version() }; println!("{}", version); } ```

Using with C++

```cpp // src/my_header.hpp

pragma once

namespace mynamespace { class MyStruct { int version; public: MyStruct(int version); int version() const; }; } ```

```rust // src/main.rs use cimport::cppimport;

cppimport!("src/myheader.hpp");

fn main() { let h = unsafe { mynamespaceMyStruct::new(2) }; println!("{}", unsafe { h.version() }); } ```

rust // build.rs fn main() { // assuming there's a libmy_cpp_lib.a println!("cargo:rustc-link-lib=my_cpp_lib"); }

Another example: ```cpp // src/fltk_wrapper.h

pragma once

include

```

```rust // src/main.rs use cimport::cppimport;

cppimport!("src/fltkwrapper.hpp");

fn main() { let version = unsafe { Fl::api_version() }; println!("{}", version); } ```

rust // build.rs fn main() { println!("cargo:rustc-link-lib=fltk"); }

Limitations