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.1.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.1-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ckernel-0.4.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b75abc31e1306d702c7aacb512554b95797a02b996f2e42c126c7ee8293c347c
MD5 96570573634e06e646cb8036185ad5a9
BLAKE2b-256 bfc7b3f90f83f3f1d378026ae987bbbdada7b50165432521039bad773804d87b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ckernel-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 20.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afc54d997a3422e037fda8bffdc265b771f7856e9c81d2a53999d64a09d37f45
MD5 dbfce36fa17c443053b0c9a8f267ea61
BLAKE2b-256 48ef88ffcea9c2950f1197334a5441e62b6a3913e031a526d29adc636e1c243a

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