Skip to content

Command line interface

CppBind provides a command-line interface for running and configuration. To see the list of available commands, use cppbind --help.

cppbind init

cppbind init

CppBind's command-line interface(CLI) allows us to create an initial config file in the current directory. To generate the initial configuration, run cppbind init under the project directory. This creates cppbind.yaml file containing the initial config example.

vars:
  out_prj_dir: "."
  src_glob:
    - ./**/*.h*
  extra_headers:
    - stdexcept
    - new
    - typeinfo
  include_dirs:
    - .
  kotlin.clang_args:
    - -D__ANDROID__
  mac.kotlin.target_arch: x86_64
  mac.kotlin.clang_args:
    - -D__ANDROID__
    - --target={{target_arch}}-none-linux-android
    - --sysroot={{get_android_ndk_sysroot(getenv('ANDROID_NDK'))}}
  mac.python.clang_args:
    - --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
  mac.swift.clang_args:
    - --sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
  kotlin.cxx_out_dir: "{{path.join(out_prj_dir, 'kotlin/wrappers')}}"
  kotlin.out_dir: "{{path.join(out_prj_dir, 'kotlin/src/main/java')}}"
  python.cxx_out_dir: "{{path.join(out_prj_dir, 'python/wrappers')}}"
  python.out_dir: "{{path.join(out_prj_dir, 'python/src')}}"
  swift.cxx_out_dir: "{{path.join(out_prj_dir, 'swift/wrappers')}}"
  swift.out_dir: "{{path.join(out_prj_dir, 'swift/src')}}"

type_vars:
  !join
  - !include std_exc_api.yaml

var_def:
  !join
  - !include variable_definitions.yaml

rules:
  kotlin.code_snippets:
    !join
    - !include kotlin/code_snippets.yaml
  python.code_snippets:
    !join
    - !include python/code_snippets.yaml
  swift.code_snippets:
    !join
    - !include swift/code_snippets.yaml

  kotlin.type_converters:
    !join
    - !include "kotlin/*_types.yaml"
  python.type_converters:
    !join
    - !include "python/*_types.yaml"
  swift.type_converters:
    !join
    - !include "swift/*_types.yaml"

  kotlin.actions:
    !join
    - !include kotlin/actions.yaml
  python.actions:
    !join
    - !include python/actions.yaml
  swift.actions:
    !join
    - !include swift/actions.yaml

Note

If you are using Windows please make sure to set standard library include path in win.include_dirs:
- C:/mingw64/lib/clang/14.0.1/include

cppbind run

cppbind run <language_list>

To generate the bindings, use the cppbind run command by providing one or more supported languages.

cppbind run kotlin swift python

Optional arguments:

--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
                  The option can set a desirable log level from possible 5 values.

--error-limit ERROR_LIMIT
                  Amount of errors, after which CppBind stops the execution and reports an error.
                  The default value is -1, which means CppBind skips all noncritical errors and only
                  after the execution reports all encountered errors.

--profile         Profiling code and generating reports

--out_prj_dir OUT_PRJ_DIR
                  The root directory of project output.
                  All includes and imports are generated relative to this directory.

--cxx_out_dir CXX_OUT_DIR
                  The root directory where all C bindings are stored.

--out_dir OUT_DIR
                  Directory where generated target language files are saved.

--target_arch TARGET_ARCH
                  Variable for setting target architecture.

Note

Most of the optional arguments are command-line level CppBind variables. For more info see cmd_line in Variable Definitions.

Note

To visualize profiling results you can use snakeViz browser based graphical viewer.
Install with pip:
pip install snakeviz
Start SnakeViz from the command line:
snakeviz profile.prof

cppbind clean

To clean all generated files from the given directory, use this command.

cppbind clean <dir>

Note

cppbind clean works by finding and removing all files that contain the CppBind banner logo.
Make sure not to remove banner logos from the generated files.


Last update: December 1, 2022