Skip to main content

IPython kernels for teaching and learning C/C++ in a Jupyter notebook, providing C/C++ syntax highlighting and a little more magic.

Project description

c-kernel

IPython kernels for teaching and learning C/C++ in a Jupyter notebook, providing C/C++ syntax highlighting, automatic compilation and a little more magic.

AutoCompileKernel

Automatically compile cells into object files or executables using the name given on the cell's first line:

Specify options in comments using //%:

Compose simple multi-file projects in a single notebook:

Interactive text input between notebook and the compiled executable:

Available options

The following options can be specified in a //% magic comment within a code cell:

Option Meaning Example
CC set the C compiler CC clang
CXX set the C++ compiler CXX clang++
CFLAGS add C compilation flags CFLAGS -Wall
CXXFLAGS add C++ compilation flags CXXFLAGS -std=c++17
LDFLAGS add linker flags LDFLAGS -lm
DEPENDS add .o dependencies, separated by spaces DEPENDS mycode.o
VERBOSE extra output from the kernel
ARGS command-line arguments to the executable ARGS arg1 arg2 etc
NOCOMPILE save and don't compile the code cell
NOEXEC save and compile, but don't execute the code cell

Installation

To install with pip:

python3 -m pip install ckernel

To install from git:

git clone git@github.com:adamtuft/c-kernel.git
python3 -m pip install ./c-kernel

Then, install the kernel(s), giving it a name and a display name of your choice. For example, to install AutoCompileKernel using clang and clang++ as the default compilers, run:

ckernel install AutoCompileKernel autocompile-clang "Auto-compile C/C++ (clang)" --user --cc clang --cxx clang++

This kernel will then be available under the name "Auto-compile C/C++ (clang)" in Jupyter:

Here are some commands for installing the kernel for use with clang and gcc, with both regular and debug versions:

python3 -m ckernel install AutoCompileKernel autocompile-gcc "Auto-compile C/C++ (gcc)" --user --cc gcc --cxx g++
python3 -m ckernel install AutoCompileKernel autocompile-gcc-debug "Auto-compile C/C++ (gcc) (debug)" --user --debug --cc gcc --cxx g++
python3 -m ckernel install AutoCompileKernel autocompile-clang "Auto-compile C/C++ (clang)" --user --cc clang --cxx clang++
python3 -m ckernel install AutoCompileKernel autocompile-clang-debug "Auto-compile C/C++ (clang) (debug)" --user --debug --cc clang --cxx clang++
jupyter kernelspec list

See ckernel install --help for all options.

Issues

Please report any issues on GitHub.

License

Licensed under the BSD 3-Clause License (see the license file).

Copyright (c) 2023, Adam Tuft

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ckernel-0.4.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ckernel-0.4.0-py3-none-any.whl (20.8 kB view details)

Uploaded Python 3

File details

Details for the file ckernel-0.4.0.tar.gz.

File metadata

  • Download URL: ckernel-0.4.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ckernel-0.4.0.tar.gz
Algorithm Hash digest
SHA256 957a984d35ac8837b4fb4c889ade2af29a6491b59e5f73ff6ccc559b49e3bb6b
MD5 5193e256a9587a821f9f77d7b7a18630
BLAKE2b-256 91b187faae7017e83a689edffc0675d2c585c998f5bab064a5a44c7eccd5eb71

See more details on using hashes here.

File details

Details for the file ckernel-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: ckernel-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for ckernel-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc5731e5b425c28d64bd29dc995ae2c99275e4f09745a7551cad55d074575838
MD5 2ffb08e6fa604a005726a68a791e82b7
BLAKE2b-256 724b7abc03a40a16ab6bca3d74ef672138137bb691f1d28d1a247abb0f674c9d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page