#sys #cuda #bindgen #darknet

sys darknet-sys

-sys crate for Rust darknet wrapper

11 releases

0.3.0 Jan 13, 2021
0.2.6 Jan 13, 2021
0.2.5 Sep 17, 2020
0.2.4 Jul 11, 2020
0.1.2 Mar 31, 2020
Download history 18/week @ 2020-09-30 7/week @ 2020-10-07 46/week @ 2020-10-14 17/week @ 2020-10-21 27/week @ 2020-10-28 16/week @ 2020-11-04 22/week @ 2020-11-11 9/week @ 2020-11-18 21/week @ 2020-11-25 8/week @ 2020-12-02 27/week @ 2020-12-09 6/week @ 2020-12-16 4/week @ 2020-12-23 5/week @ 2020-12-30 3/week @ 2021-01-06 50/week @ 2021-01-13

66 downloads per month
Used in darknet

MIT license

49K SLoC

C 30K SLoC // 0.1% comments Rust 12K SLoC // 0.0% comments C++ 2.5K SLoC // 0.1% comments Python 2K SLoC // 0.2% comments Visual Studio Project 1.5K SLoC Shell 247 SLoC // 0.2% comments PowerShell 203 SLoC // 0.1% comments Batch 199 SLoC // 0.0% comments Visual Studio Solution 140 SLoC C# 72 SLoC // 0.0% comments

Main crate: darknet

darknet-sys: FFI bindings to AlexeyAB's Darknet


Get the crate by adding the dependency to your Cargo.toml.

darknet-sys = "0.3"

If you clone the repository manually, run git submodule init && git submodule update --recursive to get all submodules.

Cargo Features

  • enable-cuda: Enable CUDA (expects CUDA 10.x and cuDNN 7.x).
  • enable-cudnn: Enable cuDNN
  • enable-opencv: Enable OpenCV.
  • runtime: Link to darknet dynamic library. For example, libdark.so on Linux.
  • dylib: Build dynamic library instead of static
  • buildtime-bindgen: Generate bindings from darknet headers.


By default, darknet-sys compiles and link to darknet statically. You can control the feature flags to change the behavior.

Method 1: Download and build from source (default)

By default, it builds and links to darknet statically.

cargo build

You can optionally enable CUDA and OpenCV features. Please read Build with CUDA section to work to CUDA properly.

cargo build --features enable-cuda,enable-opencv

Method 2: Build with custom source

If you prefer to build with your darknet source, fill the source directory to the DARKNET_SRC environment variable. It expects a CMakeLists.txt in that directory.

export DARKNET_SRC=/path/to/your/darknet/repo
cargo build

Method 3: Link to darknet dynamic library

With runtime feature, darknet-sys will not compile the darknet source code and instead links to darknet dynamically. If you are using Linux, make sure libdark.so is installed on your system.

cargo build --feature runtime

Re-generate bindings

With buildtime-bindgen feature, darknet-sys re-generates bindings from headers. It guesses the header file paths according to feature flags. The option is necessary only when darkent is updated or modified.

If you prefer to your (possibly modified) header files, fill the header directory to DARKNET_INCLUDE_PATH environment variable.

Build with CUDA

Please check both CUDA 10.x and cuDNN 7.x are installed and versions are correct.

They are not installed to standard paths on most systems. Please add the CUDA library directory to LIBRARY_PATH environment variable before building. For example on Ubuntu and CUDA 10.1,

env LIBRARY_PATH=/usr/local/cuda-10.1/lib64
cargo build --features enable-cuda


MIT license.


Huge thanks to jerry73204

No runtime deps