安装precimonious

安装gcc7.5.0,编译llvm3.0需要

#clone gcc
git clone git://gcc.gnu.org/git/gcc.git
#切换到7.5.0分支
git checkout Releases/gcc-7.5.0
# 安装依赖gmp、mpc、mpfr、isl
# 使用gcc自带脚本安装
./contrib/download_prerequisites
# 配置
mkdir build;cd build
../configure --prefix=/home/lx/local/precimonious/gcc-7.5.0 --enable-bootstrap --enable-checking=release --enable-languages=c,c++ --disable-multilib --disable-libsanitizer
# 编译-j7使用7个核心,-k表示遇到错误继续编译
make -j7 -k 2>&1 | tee build.log

# 配置gcc环境变量,写在脚本里
export PATH=/home/lx/local/precimonious/gcc-7.5.0/bin:$PATH
export LD_LIBRARY_PATH=/home/lx/local/precimonious/gcc-7.5.0/lib:/home/lx/local/precimonious/gcc-7.5.0/lib64:$LD_LIBRARY_PATH
export CPLUS_INCLUDE_PATH=/home/lx/local/precimonious/gcc-7.5.0/include/c++/7.5.0:$CPLUS_INCLUDE_PATH
export C_INCLUDE_PATH=/home/lx/local/precimonious/gcc-7.5.0/include/c++/7.5.0:$C_INCLUDE_PATH

错误

../../../../libsanitizer/sanitizer_common/sanitizer_internal_defs.h:261:72: error: size of array ‘assertion_failed__1150’ is negative
     typedef char IMPL_PASTE(assertion_failed_##_, line)[2*(int)(pred)-1]
                                                                        ^
解决方法:
./configure --disable-libsanitizer

安装llvm-3.0,precimonious使用了clang和llvm的动态库

# precimonious要求安装slurm-3.0
# 源码下载地址 https://releases.llvm.org/download.html#3.0
# 解压
tar -xf llvm-3.0.tar.gz
tar -xf clang-3.0.tar.gz
mv clang-3.0 ./llvm-3.0/tools/
# 修改clang-3.0为clang,不然不会编译clang
mv ./llvm-3.0/tools/clang-3.0 ./llvm-3.0/tools/clang
cd llvm-3.0
mkdir build
cd build
#修改编译器使用的c++标准
export CXXFLAGS='-std=c++98'
../configure \
--prefix=/home/lx/local/precimonious/llvm-3.0 #安装位置
--enable-shared #安装precimonious要求的
CC=/usr/bin/gcc #C编译器的绝对路径
CXX=/usr/bin/g++ #c++编译器的绝对路径
#完整配置命令
../configure --prefix=/home/lx/local/precimonious/llvm-3.0 --enable-shared CC=/home/lx/local/precimonious/gcc-7.5.0/bin/gcc CXX=/home/lx/local/precimonious/gcc-7.5.0/bin/g++
#开始编译
make -j 2>&1 | tee build.log # make -n可以看一下要执行哪些命令,但是不会编译
make install

错误解决

/home/lx/download/precimonious/llvm-3.0.src/include/llvm/ADT/IntervalMap.h:1980:32: error: use 'template' keyword to treat 'newNode' as a dependent template name
    Node[NewNode] = this->map->newNode<NodeT>();
                               ^
                               template
解决方法:在newNode前面加一个template,Node[NewNode] = this->map->template newNode<NodeT>();
/home/lx/download/precimonious/llvm-3.0.src/include/llvm/ADT/PointerUnion.h:266:22: error: use 'template' keyword to treat 'is' as a dependent template name
      return Ty(Val).is<T>();
                     ^
                     template
/home/lx/download/precimonious/llvm-3.0.src/include/llvm/ADT/PointerUnion.h:279:22: error: use 'template' keyword to treat 'get' as a dependent template name
      return Ty(Val).get<T>();
同样是需要加template
/usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lgcc: No such file or directory
/usr/bin/ld: cannot find -lgcc_s: No such file or directory

clang -v hello.c 查看库搜索目录,然后将缺失的库链接,gcc11编译的时候需要这样做,gcc7.5.0可能由于编译前将gcc的库和头文件都写入了环境变量,因此不会出现这个问题。
编译好clang后,编译c文件,发生segmen fault错误,可能是gcc编译版本问题,gcc11编译llvm3.0会出现这个问题,用gcc7.5.0编译clang可以正常运行。
configure:2090: clang --version >&5
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `CXXABI_1.3.13' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by clang)

llvm会优先使用clang的编译器。所以configure的时候最好指定编译器的绝对路径
error: ‘class llvm::StringRef’ has no member named ‘upper’

可能因为之前直接用mv指令,使用clang3.1覆盖clang3.0缘故。

安装完之后clang编译程序出现
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `CXXABI_1.3.13' not found (required by clang)
clang: /home/lx/local/precimonious/gcc-7.5.0/lib64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by clang)

这是因为使用的clang是clang9.0,是我之前用gcc11安装的,而现在使用的库是gcc7.5.0的库,因此出现这个问题。

检查动态库
strings /usr/lib64/libstdc++.so.6 | grep GLIBC
这个命令可以查看动态库中的GLIBC版本

安装python-2.7.18,scons要求,必须源码编译安装python2.7,否则没有wininst-6.exe

#源码下载网址:https://www.python.org/downloads/source/
cd python-2.7
mkdir build
cd build
../configure --prefix=/home/lx/local/precimonious/python-2.7
make && make install

安装scons-2.3.0,precimonious要求

# precimonious要求安装scons,且版本不能太新,precimonious是14年的,因此装14年之前的
# 下载地址:https://scons.org/pages/download.html
# 安装步骤在scons-2.3.0/README-rst 讲的很清楚
#将python加入path环境变量
export PATH=/home/lx/local/python-2.7/bin:$PATH
#安装scons
python bootstrap.py
cd build/scons
python setup.py install
#scons的执行文件装在了python的bin目录,模块装在了python的sitepackage文件夹

错误

Warning: Can't read registry to find the necessary compiler setting
Make sure that Python modules _winreg, win32api or win32con are installed.
error: [Errno 2] No such file or directory: '/usr/lib/python2.7/distutils/command/wininst-6.0.exe', /usr/lib/python2.7/distutils/command/wininst-6.0.exe not included in the Debian packages.
scons: *** [build/scons/dist/scons-2.3.0.win32.exe] Error 1

错误解释:该错误是因为linux自带的python不包含wininst-6.0.exe ,需要下载python源码包进行编译安装,就可以包含wininst-6.0.exe。

安装precimonious 按照github流程

写一个脚本precimonious_env.sh添加环境变量,包括之前的gcc、llvm和python环境变量

#! /bin/bash

# gcc7.5.0
export PATH=/home/lx/local/precimonious/gcc-7.5.0/bin:$PATH
export LD_LIBRARY_PATH=/home/lx/local/precimonious/gcc-7.5.0/lib:/home/lx/local/precimonious/gcc-7.5.0/lib64:$LD_LIBRARY_PATH
export CPLUS_INCLUDE_PATH=/home/lx/local/precimonious/gcc-7.5.0/include/c++/7.5.0:$CPLUS_INCLUDE_PATH
export C_INCLUDE_PATH=/home/lx/local/precimonious/gcc-7.5.0/include/c++/7.5.0:$C_INCLUDE_PATH
# llvm3.0
export LD_LIBRARY_PATH=/home/lx/local/precimonious/llvm-3.0/lib:$LD_LIBRARY_PATH
export PATH=/home/lx/local/precimonious/llvm-3.0/bin:$PATH
# python2.7.18,scons2.3.0
export PATH=/home/lx/local/precimonious/python-2.7/bin:$PATH
#precimonious
export CORVETTE_PATH=/home/lx/download/precimonious/precimonious-master
export LLVM_COMPILER=clang
添加执行权限
chmod u+x precimonious_env.sh

执行,必须要有source,才能在当前环境生效
source ./precimonious_env.sh

cd src
scons -Uc
scons -U
scons -U test // to run the regression test

错误

src/CreateIDBitcode.cpp: In member function 'bool CreateIDBitcode::runOnFunction(llvm::Function&)':
src/CreateIDBitcode.cpp:29:73: error: taking address of rvalue [-fpermissive]
   29 |       string instIdStr = static_cast<ostringstream*>( &(ostringstream() << instId) )->str();
      |                                                        ~~~~~~~~~~~~~~~~~^~~~~~~~~~

错误分析,可能对语法要求更高。将这段代码改为
ostringstream oss;
oss << instId;
string instIdStr = static_cast<ostringstream*>(&oss  )->str();
可以使用g++ -dM -E -x c++  /dev/null | grep -F __cplusplus查看默认的c++标准。
g++: error: unrecognized command-line option '-Wl'; did you mean '-W'?

解决方法;把src/SConscript中第57行的-Wl改为-W。-Wl是传递选项给链接器,-W用来开启警告选项。

遇到的一些其他错误

	1.编译llvm3.0出现的错误:error:no match for 'operator<<'...
因为没用c++98标准
	2.安装precimonious出现的错误:NameError:name 'SourceCode' is not defined
因为scons的版本太高,应该用低版本的
	3.error:unrecognized command line option '-Wl';
需要修改precimonious-master/src/SConscript中的-Wl部分
	4./usr/bin/ld: cannot find -lLLVM-3.0
必须用./configure --enable-shared的方式安装llvm3.0
	5.undefined reference to
要么是c++标准的问题,要么是版本的问题
	6./bin/bash^M:bad interpreter
因为下载preci的安装包下到了windows,windows和linux的断行符不同,推荐github下载安装包使用zip格式。
	
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值