# Bindgen basic help

**URL:** <https://users.rust-lang.org/t/bindgen-basic-help/11478>\
**Category:** help\
**Created:** [June 22, 2017, 9:54am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478 "2017-06-22T09:54:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![0xSpock](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/0xspock/32/2926_2.png) [@0xSpock](https://users.rust-lang.org/u/0xSpock)\
**Post date:** [June 22, 2017, 9:54am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/1 "2017-06-22T09:54:26Z")

</div>

Hi,  
I'm trying to use bindgen to create bindings to C++ code (kea dhcp server).  
I'm following guides but I've stumbled on first step.. 🙂  
My Cargo.toml contains required declarations:

```
[package]
build = "build.rs"

[dependencies]
bindgen = "0.26.1"

```

build.rs in my crate root folder have content according to example from bindgen:

```
extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
// code here

```

And I'm getting error when running cargo build:

```
error[E0463]: can't find crate for `bindgen`
 --> build.rs:1:1
  |
1 | extern crate bindgen;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

```

What I'm doing wrong ?

---

<div class="post-metadata">

**Author:** ![Keats](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/keats/32/1922_2.png) [@Keats](https://users.rust-lang.org/u/Keats)\
**Post date:** [June 22, 2017, 9:58am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/2 "2017-06-22T09:58:33Z")

</div>

Put it in `[build-dependencies]` like [https://github.com/compass-rs/sass-rs/pull/11/files#diff-3f5590e43a4a71147163b6b694dc7c66R16](https://github.com/compass-rs/sass-rs/pull/11/files#diff-3f5590e43a4a71147163b6b694dc7c66R16)

---

<div class="post-metadata">

**Author:** ![0xSpock](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/0xspock/32/2926_2.png) [@0xSpock](https://users.rust-lang.org/u/0xSpock)\
**Post date:** [June 22, 2017, 10:15am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/3 "2017-06-22T10:15:18Z")

</div>

Ha,

This helped. Thanks !

Why such information is not present in any bindgen doc/example ?

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [June 23, 2017, 9:20am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/4 "2017-06-23T09:20:23Z")

</div>

> [@0xSpock](#):
>
> Why such information is not present in any bindgen doc/example

I just had a skim through their guide and found [this](https://servo.github.io/rust-bindgen/tutorial-1.html).

---

<div class="post-metadata">

**Author:** ![megha1906](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/megha1906/32/19189_2.png) [@megha1906](https://users.rust-lang.org/u/megha1906)\
**Post date:** [January 22, 2021, 7:18am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/5 "2021-01-22T07:18:10Z")

</div>

Still now working. already kept it in [build-dependencies]

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [January 22, 2021, 8:24am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/6 "2021-01-22T08:24:59Z")

</div>

It works fine on my machine.

Can you share the code or error messages?

---

<div class="post-metadata">

**Author:** ![megha1906](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/megha1906/32/19189_2.png) [@megha1906](https://users.rust-lang.org/u/megha1906)\
**Post date:** [January 22, 2021, 9:39am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/7 "2021-01-22T09:39:53Z")

</div>

error[E0463]: can't find crate for `bindgen`  
--\> build.rs:1:1  
|  
1 | extern crate bindgen;  
| ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

in Cargo.toml:

[build-dependencies]  
bindgen = "0.53.1"

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [January 22, 2021, 9:54am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/8 "2021-01-22T09:54:55Z")

</div>

That's odd, it works for me.

```rust
$ cargo --version
cargo 1.51.0-nightly (a73e5b7d5 2021-01-12)
$ rustc --version --verbose
rustc 1.51.0-nightly (c5a96fb79 2021-01-19)
binary: rustc
commit-hash: c5a96fb7973649807a7943e7395456db158dcab6
commit-date: 2021-01-19
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly
LLVM version: 11.0.1

$ cargo new --lib repro
$ cd repro

$ cat Cargo.toml
[package]
name = "repro"
version = "0.1.0"
authors = ["Michael-F-Bryan <michaelfbryan@gmail.com>"]
edition = "2018"
build = "build.rs"

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

[dependencies]

[build-dependencies]
bindgen = "0.56.0"

$ cat build.rs
extern crate bindgen;

fn main() { }

$ cat src/lib.rs
#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert_eq!(2 + 2, 4);
    }
}

$ cargo build
   Compiling repro v0.1.0 (/tmp/repro)
    Finished dev [unoptimized + debuginfo] target(s) in 0.10s

```

---

<div class="post-metadata">

**Author:** ![megha1906](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/megha1906/32/19189_2.png) [@megha1906](https://users.rust-lang.org/u/megha1906)\
**Post date:** [January 22, 2021, 10:16am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/9 "2021-01-22T10:16:08Z")

</div>

Do i need to "cargo build" or rustc build.rs. cargo build gives different errors

cannot find macro `llvm_asm` in this scope  
/mod.rs:16:5  
|  
16 | llvm\_asm!("syscall"  
| ^^^^^^^^

**strong text**

---

<div class="post-metadata">

**Author:** ![megha1906](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/megha1906/32/19189_2.png) [@megha1906](https://users.rust-lang.org/u/megha1906)\
**Post date:** [January 22, 2021, 10:20am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/10 "2021-01-22T10:20:04Z")

</div>

cargo --version  
cargo 1.43.0  
$ rustc --version --verbose  
rustc 1.43.0  
binary: rustc  
commit-hash: unknown  
commit-date: unknown  
host: x86\_64-unknown-linux-gnu  
release: 1.43.0  
LLVM version: 9.0

---

<div class="post-metadata">

**Author:** ![Michael-F-Bryan](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/michael-f-bryan/32/28749_2.png) [@Michael-F-Bryan](https://users.rust-lang.org/u/Michael-F-Bryan)\
**Post date:** [January 22, 2021, 10:47am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/11 "2021-01-22T10:47:06Z")

</div>

You should be building with `cargo build`. Cargo is the Rust package manager and looks after downloading dependencies and making sure they get compiled into your program.

For more on how to compile things I'd recommend reading the corresponding chapter from the book:

[https://doc.rust-lang.org/book/ch01-03-hello-cargo.html](https://doc.rust-lang.org/book/ch01-03-hello-cargo.html)

> [@megha1906](#):
>
> cannot find macro `llvm_asm` in this scope

[The `llvm_asm!()` macro](https://doc.rust-lang.org/stable/unstable-book/library-features/llvm-asm.html) was an unstable feature for telling LLVM (the thing inside Rust which generates machine code) to insert some assembly instructions. You'll need to opt into this unstable/incomplete feature it by adding `#![feature(llvm_asm)]` to the top of your `lib.rs` or `main.rs`.

I believe it's since been superseded by [the `asm!()` macro](https://doc.rust-lang.org/stable/unstable-book/library-features/asm.html).

---

<div class="post-metadata">

**Author:** ![megha1906](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/megha1906/32/19189_2.png) [@megha1906](https://users.rust-lang.org/u/megha1906)\
**Post date:** [January 22, 2021, 11:05am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/12 "2021-01-22T11:05:04Z")

</div>

should i just add `#![feature(llvm_asm)]` in the first line of lib.rs?

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/steffahn/32/47569_2.png) [@steffahn](https://users.rust-lang.org/u/steffahn)\
**Post date:** [January 12, 2023, 9:02am UTC](https://users.rust-lang.org/t/bindgen-basic-help/11478/13 "2023-01-12T09:02:11Z")

</div>


