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 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.2.0.tar.gz (17.7 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.2.0-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ckernel-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1e76ca5c7fb36d77250d3344095e9fce9aec637c13fd79c507e2f8b387c1fae5
MD5 9343d97a16179c8f8249f535d34c5fd3
BLAKE2b-256 6cf6c366a558e0d323f46595a1cc6f9def50cceb003c4c1f17e5738a1bd18019

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ckernel-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 18.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4567d17ce0cdc139373d9a4e1e47d9b848bd8edfdcf65c4178c57eeeddfd964c
MD5 07cae95b69e4d54ded8d293958c726d7
BLAKE2b-256 37293206c1c8e2c99e60b9059c9ba4fe9963bb0a47c9eb1bce7eaec060030804

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