一、环境:
虚拟机:
(1)系统:centos7.5_1804(64bit)版本
(2)软件环境:git、python3.5.3、Jupyter4.4.0
二、下载安装脚本:
资源及安装说明:https://github.com/root-project/cling
(1)下载安装脚本文件方式:
wget https://raw.githubusercontent.com/root-project/cling/master/tools/packaging/cpt.py
#由于网站在国外,下载这个文件很慢,不建议这样操作。
(2)克隆软件仓库方式:
(ccl353) [python@centos75 test]$ git clone https://github.com/root-project/cling.git
#此方式由于使用了镜像站点,速度很快。命令执行完成后,在当前目录下产生cling目录。
三、cmake安装:
(ccl353) [python@centos75 test]$ pip install cmake==3.11.4
#cmake版本要求3.6.4以上,此处指定版本安装3.11.4版,也可安装最新版,没有特殊要求。
四、安装过程:
1、c++核心代码编译过程:
(ccl353) [python@centos75 test]$ cd cling/tools/packaging
(ccl353) [python@centos75 packaging]$ ./cpt.py --check-requirements && ./cpt.py --create-dev-env Debug --with-workdir=./cling-build/
#此过程很长,包括编译过程中下载文件的时间及编译过程的时间,以小时计,中间有几个错误需要逐一解决:
(1)“c++: 编译器内部错误:已杀死(程序 cc1plus)”——内存不足,增加内存或swap交换缓存。
(2)“collect2: 错误:ld 以信号 9 [已杀死] 退出。”——swap交换缓存不足,增加swap交换缓存
(3)“CMake Error at tools/clang/tools/driver/cmake_install.cmake:41 (file):
file INSTALL cannot copy file
"/home/python/projects/test/cling/tools/packaging/cling-build/builddir/bin/clang-5.0"
to "/tmp/cling-obj/bin/clang-5.0".”——目标磁盘空间不足,增加/tmp目录挂载磁盘空间。
(4)“make: *** [install] 错误 1
subprocess.CalledProcessError: Command 'make -j4 install' returned non-zero exit status 2”——这个错误提示可不用理会,前面的错误解决后,这个错误就不会发生了,估计与前面的磁盘空间不足问题相关联。
最终结果:
...
[100%] Built target cling
[100%] Running the Cling regression tests
lit.py: /home/python/projects/test/cling/tools/packaging/cling-build/cling-src/tools/cling/test/lit.cfg:261: note: using cling: '/home/python/projects/test/cling/tools/packaging/cling-build/builddir/./bin/cling'
lit.py: /home/python/projects/test/cling/tools/packaging/cling-build/cling-src/tools/cling/test/lit.cfg:272: note: Running tests from build tree
Testing Time: 423.23s
Expected Passes : 121
Expected Failures : 13
Unsupported Tests : 9
[100%] Built target check-cling
#编译基本完成,但不是很理想,有13个测试未通过,但不影响使用。
#在/home/python/projects/test/cling/tools/packaging/cling-build/目录下有一新生成目录"cling-CentOS Linux-7.5.1804-x86_64-0.6~dev-6238cda",应该是编译后的c++核心文件目录
2、配置环境变量,并测试c++环境:
(1)添加PATH变量:
(ccl353) [python@centos75 bin]$ vi /home/python/.bashrc
...
# User specific aliases and functions
export PATH=$PATH:/home/python/projects/test/cling/tools/packaging/cling-build/"cling-CentOS Linux-7.5.1804-x86_64-0.6~dev-6238cda"/bin
(2)激活环境变量:
(ccl353) [python@centos75 bin]$ source /home/python/.bashrc
(3)测试c++环境:
(ccl353) [python@centos75 bin]$ cd /home/python
[python@centos75 ~]$ cling
****************** CLING ******************
* Type C++ code and press enter to run it *
* Type .q to exit *
*******************************************
[cling]$
#现此界面,表明c++基本可用!
3、安装Jupyter环境下的c++核心(安装说明文档在:/home/python/projects/test/cling/tools/Jupyter/README.md):
[python@centos75 ~]$ cd /home/python/projects/test/cling/tools/packaging/cling-build/cling-CentOS Linux-7.5.1804-x86_64-0.6~dev-6238cda/share/cling/Jupyter/kernel
(ccl353) [python@centos75 kernel]$ ls
cling-cpp11 cling-cpp17 cling.ipynb scripts
cling-cpp14 cling-cpp1z clingkernel.py setup.py
(ccl353) [python@centos75 kernel]$ pip install -e .
4、注册C++17/C++1z/C++14/C++11的kernelspec:
(ccl353) [python@centos75 kernel]$ jupyter-kernelspec install --user cling-cpp17
[InstallKernelSpec] Installed kernelspec cling-cpp17 in /home/python/.local/share/jupyter/kernels/cling-cpp17
(ccl353) [python@centos75 kernel]$ jupyter-kernelspec install --user cling-cpp1z
[InstallKernelSpec] Installed kernelspec cling-cpp1z in /home/python/.local/share/jupyter/kernels/cling-cpp1z
(ccl353) [python@centos75 kernel]$ jupyter-kernelspec install --user cling-cpp14
[InstallKernelSpec] Installed kernelspec cling-cpp14 in /home/python/.local/share/jupyter/kernels/cling-cpp14
(ccl353) [python@centos75 kernel]$ jupyter-kernelspec install --user cling-cpp11
[InstallKernelSpec] Installed kernelspec cling-cpp11 in /home/python/.local/share/jupyter/kernels/cling-cpp11
(ccl353) [python@centos75 kernel]$
#此时,运行jupyter notebook --no-browser --ip=* --port=8888,浏览器登录notebook,在界面的右部点击new,可以看到新增的c++核心。
4、Jupyter notebook的c++核心运行不稳定的处理:
上述安装完成好,在使用notebook过程发现c++核心不稳定,观察Jupyter notebook服务器的log信息,发现错误提示“RuntimeError: Cannot find /home/python/projects/test/cling/tools/packaging/cling-build/cling-CentOS Linux-7.5.1804-x86_64-0.6~dev-6238cda/lib/libclingJupyter.{so,dylib,dll}”,分析应该是缺少libclingJupyter相关文件导致。回头观察编译过程,发现缺少的文件已在编译过程中生成在/tmp/cling-obj/lib目录下,只是没有拷贝到适当位置。作如下处理:
从目录/tmp/cling-obj/lib拷贝libclingJupyter.so.5.0.0文件到编译结果的lib目录,并做两个软连接文件:
(ccl353) [python@centos75 packaging]$ cp /tmp/cling-obj/lib/libclingJupyter.so.5.0.0 /home/python/projects/test/cling/tools/packaging/cling-build/"cling-CentOS Linux-7.5.1804-x86_64-0.6~dev-6238cda"/lib
(ccl353) [python@centos75 lib]$ ln -s libclingJupyter.so.5.0.0 libclingJupyter.so.5
(ccl353) [python@centos75 lib]$ ln -s libclingJupyter.so.5 libclingJupyter.so
(ccl353) [python@centos75 lib]$ ll
总用量 1144268
drwxrwxr-x 3 python python 4096 8月 22 20:54 clang
lrwxrwxrwx 1 python python 20 8月 22 21:32 libclingJupyter.so -> libclingJupyter.so.5
lrwxrwxrwx 1 python python 24 8月 22 21:31 libclingJupyter.so.5 -> libclingJupyter.so.5.0.0
-rwxr-xr-x 1 python python 1171719248 8月 22 21:08 libclingJupyter.so.5.0.0
#经上述处理过程后,jupyter notebook下的c++核心已能稳定运行。
5、小结:
jupyter notebook的c++核心支持的安装编译过程超过了我的预期,总体看需要注意几个要点:
(1)内存要大(至少4G,实际使用了6G)
(2)swap交换缓存要大(实际使用达17G,编译时设置swap空间为30G)
(3)/tmp目录空间要大(实际使用达23G,编译过程中专门配置了一块100G磁盘做/tmp挂载盘)
(4)编译时间长(实际编译估计在10小时左右,中间涉及编译过程中还要从网上下载文件,编译代码量达G数量级,故时间很长)
(5)还有部分工作需要手动操作(如:拷贝libclingJupyter.so.5.0.0等文件)
6、附:
小技巧:
(1)编译过程中,可另开终端使用free和df命令观察内存及磁盘使用情况,辅助观察编译过程的资源占用情况。
(2)原机swap交换分区只有1.3G,可通过如下命令增加swap交换空间(应使用root权限):
[root@centos75 home]# dd if=/dev/zero of=/home/swapfile bs=1M count=30000
[root@centos75 home]# mkswap /home/swapfile
[root@centos75 home]# swapon /home/swapfile
[root@centos75 home]# swapon -s
文件名 类型 大小 已用 权限
/dev/sda3 partition 1362940 0 -1
/home/swapfile file 30719996 0 -2