IT狗工作室C语言

Jupyter-notebook交互式执行C++ 代码

2020-05-03  本文已影响0人  铁甲万能狗

搭建环境

按照https://root.cern.ch/cling-build-instructions官网的提示,手动编译Cling编译器,分别检查llvm,clang和cling:

mkdir ~/cling
git clone http://root.cern.ch/git/llvm.git ~/cling
cd ~/cling
git checkout cling-patches
cd tools
git clone http://root.cern.ch/git/cling.git
git clone http://root.cern.ch/git/clang.git
cd clang
git checkout cling-patches
cd ../..

然后使用CMake进行配置和构建Cling,我们将构建后的Cling编译器安装到/usr/local/cling目录,这个过程要等上一个小时不等....

cd ~/cling
sudo mkdir /usr/local/cling
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/cling -DCMAKE_BUILD_TYPE=Release ../
cmake --build .
cmake --build . --target install

安装完成Cling后,我们可以看到目录下的Jupyter子目录已经预供给我们几个流行的C++编译器的Jupyter内核


安装C++ 内核

安装C++内核前,请确保已经安装python3环境下已经安装ipython

sudo pip3 install ipython

重定向到带有setup.py文件的所在目录

cd /usr/local/cling/share/cling/Jupyter/kernel
sudo pip3 install -e .

安装你需要的C++内核版本,例如C++17

jupyter kernelspec install --user ./cling-cpp17

环境变量设定PATH,告知启动的Jupyter,cling交互编译器所在的执行路径

vi ~/.bashrc
export PATH="$PATH:/usr/local/lib/jre/bin:/usr/local/lib/jre/lib:/usr/l    ocal/cling/bin"

Bingo,测试OK,这样你就可以交互式地执行各种C++代码了


上一篇下一篇

猜你喜欢

热点阅读