编译Mesa时的一个经典错误!
错误详情:
checking for RADEON... yes
configure: error: LLVM is required to build Gallium R300 on x86 and x86_64
注意,这里需要自己下载安装>3.1版本的LLVM,因为用sudo apt-get install llvm装的版本不够新,用不了,还是会提示同样错误。因为之前(这里)装过,记得这个错误,所以下文是直接下载3.5版本,编译安装。
下载LLVM 3.5.0,
http://llvm.org/releases/download.html#3.5
LLVM source code(.sig)
下载的压缩文件为:llvm-3.5.0.src.tar.xz
sudo tar -xvf llvm-3.5.0.src.tar.xz
cd llvm-3.5.0.src/
sudo ./configure
会提示如下错误:
checking whether GCC is new enough... no
configure: error: The selected GCC C++ compiler is not new enough to build LLVM. Please upgrade to GCC 4.7. You may pass --disable-compiler-version-checks to configure to bypass these sanity checks.
只需升级一下gcc,g++版本,不会可以点这里
sudo ./configure
sudo makesudo make install
完成。
但是,继续编译Mesa,sudo ./configure --disable-dri3,却报如下错误:
checking for RADEON... yes
configure: error: Could not find llvm shared libraries:
Please make sure you have built llvm with the --enable-shared option
and that your llvm libraries are installed in /usr/local/lib
If you have installed your llvm libraries to a different directory you
can use the --with-llvm-prefix= configure flag to specify this directory.
NOTE: Mesa is attempting to use llvm shared libraries by default.
If you do not want to build with llvm shared libraries and instead want to
use llvm static libraries then add --disable-llvm-shared-libs to your configure
invocation and rebuild.
开始以为是configure文件里的option(BUILD_SHARED_LIBS "Build all libraries as shared libraries instead of static" ON)类似问题。但是:
sudo gedit configure
打开果然搜索到类似的一个地方,但是人家说明默认是已经开启的!!
--enable-shared Build a shared library and link tools against it (default is NO)
这次深究了一下,对比了二进制源码和我已经成功编译的版本区别在哪里?于是进入/usr/local/lib,查看到了很多LLVM的包,与“clang+llvm-3.3-amd64-Ubuntu-12.04.2”对比,发现少了二进制中有的clang开头的很多libclang*.a的文件。原来确实不是我以前看到说的那样BUILD_SHARED_LIBS没设置为ON,而是因为我没有安装Clang包。
LLVM和Clang是2个库,只是经常一起用,官网提供的二进制预编译好的包是将2者编译放在一起了,所以我原来直接用他们2进制包没问题。但是独立编译安装LLVM后,却一直提示“error: Could not find llvm shared libraries”,原来是缺少了Clang包,应该装一下就行:
下载LLVM 3.5.0下面的Clang源文件,
http://llvm.org/releases/download.html#3.5
sudo tar -xvf cfe-3.5.0.src.tar.xz
cd cfe-3.5.0.src
gedit README.txt
可以看到这么一句提醒:
Welcome to Clang. This is a compiler front-end for the C family of languages (C, C++, Objective-C, and Objective-C++)which is built as part of the LLVM compiler infrastructure project. 同时可以参考这里或这里,可知Clang的编译是需要放到LLVM/tools文件夹下面。具体编译方法如下:
1)将下载后解压得到的clang的源代码文件夹名称改为clang:
sudo cp -r cfe-3.5.1.src clang cd llvm-3.5.0.src/tools/ sudo mv ../../clang/ ./
cd llvm-3.5.0.src/ sudo ./configure sudo make sudo make install
谁知,装完继续编译Mesa仍然还报同样错误?编译的哪里不对?
毕竟我目的不是老折腾这个库,又有点想放弃编译,直接用官网提供的编译好的了,现在适合我系统的版本的已经有LLVM 3.4.2的Pre-built Binaries:
Checkout Compiler-RT:
Build LLVM and Clang:
编译时间太长,每次make大约需要等待1.5小时,8G内存的新电脑尚且如此,一般用户哪经得起这折腾啊????再说我也不是闲的没事的人,所以我决定这次编译还是不行的话,我就直接用3.4.2的Pre-built Binaries。以前用过3.3的没问题,这次想试试3.4.2的。
漫长等待过后,make install完成,发现/usr/local/lib/clang/3.5.0/lib/linux目录出现了。里面有那些libclang_rt.*.a等若干库。欣喜!
悲剧的是,问题依旧:
configure: error: Could not find llvm shared libraries:
Please make sure you have built llvm with the --enable-shared option
and that your llvm libraries are installed in /usr/local/lib
If you have installed your llvm libraries to a different directory you
can use the --with-llvm-prefix= configure flag to specify this directory.
NOTE: Mesa is attempting to use llvm shared libraries by default.
If you do not want to build with llvm shared libraries and instead want to
use llvm static libraries then add --disable-llvm-shared-libs to your configure
invocation and rebuild.
我想应该是二进制版本是完全编译的,我这里编译的始终是缺少部分包(比如LibC++,Clang Tools Extra,Dragonegg...),不太了解官网那一堆源文件到底应该装哪些:
Clang source code (.sig)
LLVM source code (.sig)
Compiler RT source code (.sig)
Dragonegg source code (.sig)
LibC++ source code (.sig)
LibC++ ABI source code (.sig)
LLDB source code (.sig)
LLD source code (.sig)
Polly source code (.sig)
OpenMP source code (.sig)
Clang Tools Extra (.sig)
LLVM Test Suite (.sig)
至少目前3.5.0版本还没有我这个系统的二进制包可用。烦了,编译到此为止,果断删除:
sudo make uninstall
现在只剩一条路了。直接用3.4.2的(clang+llvm-3.4.2-x86_64-unknown-ubuntu12.04.xz。下载后,解压,将解压得到的文件夹:
cd clang+llvm-3.4.2-x86_64-unknown-ubuntu12.04/
ls
bin docs include lib share
分别拷贝到/usr/local/下对应的文件夹内。悲剧的是依旧同样错误“Could not find llvm shared libraries”。这似乎是一个涉及到llvm-config的bug。llvm-defaults: please provide a usable llvm-config executable in every llvm version。please consider shipping a usable llvm-config executable in every llvm version. Currently it is shipped only for the recommended version, other versions have only a llvm-config suffixed with the version (e.g. llvm-config-3.2). This will ease llvm usage since one could just use plain llvm-config which should point to the current installed version, or, if more are available, to a suggested one.
现在唯一想做的就是用低版本,稳定版本!!!尤其对于我这种新手对于版本太多的Linux库又不是很熟的情况下,以后千万不要盲目追求新版本。
原来试过3.3版本的二进制版(clang+llvm-3.3-amd64-Ubuntu-12.04.2.tar.gz),worked。但是今天同样方法试了,却不行,怪的是也报“Could not find llvm shared libraries”。因为之前手动拷贝3.4.2版本的二进制,而且不知道是否删除干净,所以我不确定问题再哪里。
最后的最后,解决这个问题的办法居然是:
我直接编译3.3版本的源文件(llvm-3.3.src.tar.gz和cfe-3.3.src.tar.gz),详细步骤在此。
将下载后解压得到的cfe-3.3.src改名为clang,并拷贝到:llvm-3.3.src/tools/目录结构如下:
<llvm-3.3.src>
tools
clang
然后编译llvm:
cd llvm-3.3.src
./configure --enable-shared=yes
sudo make
sudo make install
安装成功后,编译Mesa,不再报这个错!
参考:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=697497
http://flexwang.me/blog/2014/07/17/ubuntu14-dot-04shang-mesa3dde-bian-yi-yu-an-zhuang/