Bindgen basic help

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.. :slight_smile:
My Cargo.toml contains required declarations:

build = ""

bindgen = "0.26.1" 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`
1 | extern crate bindgen;
  | ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

What I'm doing wrong ?

Put it in [build-dependencies] like


This helped. Thanks !

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

I just had a skim through their guide and found this.

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

It works fine on my machine.

Can you share the code or error messages?

error[E0463]: can't find crate for bindgen
1 | extern crate bindgen;
| ^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

in Cargo.toml:

bindgen = "0.53.1"

That's odd, it works for me.

$ 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
name = "repro"
version = "0.1.0"
authors = ["Michael-F-Bryan <>"]
edition = "2018"
build = ""

# See more keys and their definitions at


bindgen = "0.56.0"

$ cat
extern crate bindgen;

fn main() { }

$ cat src/
mod tests {
    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

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

cannot find macro llvm_asm in this scope
16 | llvm_asm!("syscall"
| ^^^^^^^^

strong text

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

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:

The llvm_asm!() macro 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 or

I believe it's since been superseded by the asm!() macro.

should i just add #![feature(llvm_asm)] in the first line of