Hello, World!
  • Home
  • Categories
  • Tags
  • Archives

C++ 直譯器 cling: jupyter notebook

Table of Contents

  • install cling
  • start C++ kernel
  • ubuntu
  • reference

https://github.com/vgvassilev/cling

一般在開發 C 或者是 C++ 的程式時 都需要 將程式碼編譯成 可執行檔 才可以運行程式

cilng 讓你可以省去這一個步驟 當你執行 cling 時 會進入到一個 shell 你可以輸入 合法的 C++ 代碼 直接執行它

可惜在這個 shell 裡面 不太容易進行編輯代碼

然而這個問題 透過 jupyter notebook 可以很完美的解決

jupyter notebook 可以 接上 cling

讓我們在 在 jupyter noteook 上執行 C++ 的程式碼

install cling

常用的 Linux 發行版本 或是 Mac cling 都有提供編譯好的 tar 檔 下載後解開 tar 檔 放到喜歡的目錄下 就算完成安裝

cd /path/to/cling
ls
bin     include lib     libexec share
cd share/cling/Jupyter/kernel

pip install -e .
jupyter-kernelspec install --user cling-cpp17
jupyter-kernelspec install --user cling-cpp14
jupyter-kernelspec install --user cling-cpp11

start C++ kernel

Make sure cling in your $PATH

On my mac, for example

export PATH=~/bin/cling_2017-05-09_mac1011/bin:$PATH
jupyter notebook

ubuntu

常用的 Linux 發行版本 cling 提供了編譯好的 tar 檔 下載後解開 tar 檔 放到喜歡的目錄下 就算完成安裝

值得注意 ubuntu 需要安裝相關的套件 否則無法順利執行

sudo apt-get update
sudo apt-get install git g++ debhelper devscripts gnupg python

reference

cling https://github.com/vgvassilev/cling

Example https://github.com/minrk/clingkernel/blob/master/cling.ipynb

On-The-Fly C++

Cling interprets C++


Published

Jun 2, 2017

Category

C++

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor