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.3.1.tar.gz (18.1 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.3.1-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ckernel-0.3.1.tar.gz
Algorithm Hash digest
SHA256 4576e59d5feed67b3d296681002d101c0cd1f7ec205c6407032354419eddbd6f
MD5 197afb9b784e26229ad073990d04ac7e
BLAKE2b-256 14f32873570aecca13a15d846a1f057b42f65b494032ee8554d9ff0e8d65efb8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ckernel-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b9e06256f1e00cee7db04461a7bee298a224c72df8058f3aca696b2372213e5
MD5 88aa2b75beff7f0ee38e9c4ff510fcf0
BLAKE2b-256 06a49bbd29f22b0e1776cbe951bba14f8afa8f38c2d6b9845afb77d4afda7398

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