Use clair-c2py manually
The following two commands generate the Python bindings and compile the corresponding Python module for our Getting Started example:
clair-c2py getting_started.cpp -- -std=c++20 `c2py_flags -i`
clang++ getting_started.cpp -std=c++20 -shared -o getting_started.so `c2py_flags`
That’s it. The Python module getting_started is ready to be used.
Let us break down the commands in more detail.
Generate Python Bindings
clair-c2py getting_started.cpp -- -std=c++20 `c2py_flags -i`
This generates the C++/Python binding file getting_started.wrap.cxx and updates the
original source file getting_started.cpp to include the generated bindings.
A companion header getting_started.wrap.hxx is also generated when the module wraps at least one class
(see Across multiple modules).
See Generate Python Bindings and Compile the Module for some more background information.
Note
Here, we assume that
c2pyis installed and thatc2py_flagsis available in the system path. The commandc2py_flags -iprovides all necessary include paths for Python.In a CMake project, we typically rely on
compile_commands.jsonin conjunction with automatic detection of Python and c2py targets (see Use CMake integration [Recommended] for more details).
Compile the Module
clang++ getting_started.cpp -std=c++20 -shared -o getting_started.so `c2py_flags`
This compiles the Python C++ extension.
Note
The command
c2py_flagsprovides all necessary include and linker paths for Python.Any C++20 compiler can be used to compile the bindings (clang, gcc, etc.). It is independent of the
clair_c2pytool and of the LLVM/clang version it is based on.