如何安装clang预制二进制文件ubuntu 12.04 [英] How to install clang pre-built binaries ubuntu 12.04

查看:124
本文介绍了如何安装clang预制二进制文件ubuntu 12.04的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对linux还是很陌生,不知道我需要在哪里放置Clang预先构建的二进制文件

I am very new to linux, and don't know where I need to put Clang pre-built binaries http://llvm.org/releases/download.html#3.3 . I download it, unpack with mouse, and add path to /bin to my $PATH, and path to /lib to $LD_LIBRARY_PATH, and add *.conf with path to my /lib to /etc/ld.so.conf.d . I even reboot my notebook.
...but still cant build my simple program with Code::Blocks GCC (error: /home/aadgrand/tmp/LLVM-3.3/final/llvm.src/lib/Support/Signals.cpp - undefined reference to `dladdr'). Text of the test programm:

#include <iostream>
#include "llvm/IR/Module.h"
#include "llvm/IR/LLVMContext.h"
using namespace std;

int main()
{
    llvm::LLVMContext &c = llvm::getGlobalContext(); // error line
    cout << "Never printed" << endl;
    return 0;
}

我还需要做什么?也许我需要使用* .sig文件?嗯?

What else I need to do? Maybe I need to use *.sig-file? Hm?

如何使用预编译的二进制文件安装CLang的问题相同? . 很抱歉重复一遍,但这确实非常有趣且重要.

Same question as How to install CLang using precompiled binaries? . Sorry for repeat, but it is really very interesting and important.

=====更新======

===== UPDATED ======

我刚刚安装了llvm-3.1,与llvm-3.4一样的错误(来自预构建的二进制文件):

I've just insalled llvm-3.1, same error like with llvm-3.4 (from pre-built binaries):

-------------- Build: Debug in test2 ---------------

Compiling: main.cpp
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
COLLECT_GCC_OPTIONS='-std=c++98' '-pg' '-g' '-v' '-Wall' '-fexceptions' '-I' '/usr/lib/llvm-3.1/include' '-c' '-o' 'obj/Debug/main.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -I /usr/lib/llvm-3.1/include -imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE /home/kpdev/projects/test2/test2/main.cpp -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase-strip obj/Debug/main.o -g -Wall -std=c++98 -version -p -fexceptions -fstack-protector -o /tmp/ccbKoBDJ.s
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
    #include "..." search starts here:
    #include <...> search starts here:
 /usr/lib/llvm-3.1/include
 /usr/include/c++/4.6
 /usr/include/c++/4.6/x86_64-linux-gnu/.
 /usr/include/c++/4.6/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.6/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 65b5171ac1bd7b3f07dbea6bdb24be3d
/home/kpdev/projects/test2/test2/main.cpp: In function ‘int main()’:
/home/kpdev/projects/test2/test2/main.cpp:11:24: warning: unused variable ‘c’ [-Wunused-variable]
COLLECT_GCC_OPTIONS='-std=c++98' '-pg' '-g' '-v' '-Wall' '-fexceptions' '-I' '/usr/lib/llvm-3.1/include' '-c' '-o' 'obj/Debug/main.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as --64 -o obj/Debug/main.o /tmp/ccbKoBDJ.s
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-std=c++98' '-pg' '-g' '-v' '-Wall' '-fexceptions' '-I' '/usr/lib/llvm-3.1/include' '-c' '-o' 'obj/Debug/main.o' '-shared-libgcc' '-mtune=generic' '-march=x86-64'



Linking console executable: bin/Debug/test2
/usr/lib/llvm-3.1/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)':
(.text+0x6c): undefined reference to `dladdr'
/usr/lib/llvm-3.1/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)':
(.text+0x187): undefined reference to `dladdr'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 1 warnings


||=== Build finished: 2 errors, 1 warnings ===|

推荐答案

您的问题的标题误导了我自己和Atropo.看起来好像 您要安装 clang C ++编译器并构建一个llvm 带有Code :: Blocks的C ++程序.

The title of your question has misled both myself and Atropo. It looked as if you want to install the clang C++ compiler and build an llvm C++ program with it in Code::Blocks.

您实际上想做的是安装clang + llvm(它们实际上是 不同的东西),并使用Code :: blocks中的 GCC 构建llvm程序. 您确实说过"Code :: Blocks GCC",但我认为那只是意味着 我在GCC上设置了Code :: Blocks,现在我想使用clang". C :: B构建日志 但是,您添加的内容表明您使用GCC构建.

What you are actually trying to do is install clang+llvm (they are actually different things) and build an llvm program with GCC in Code::blocks. You did say "Code::Blocks GCC", but I assumed that just meant "I had Code::Blocks set up with GCC and now I want to use clang". The C::B build log that you have added, however, shows that you building with GCC.

鉴于您正在使用GCC构建llvm程序,目前尚不清楚原因 您要安装clang编译器.也许您想使用clang但您 不知道Code :: Blocks可以支持clang编译器,或者不知道如何 配置C :: B以使用clang.但是,让我们一次采取一件事.您可以可以构建 如果您只是正确设置了东西,这个带有gcc的llvm程序. - 一个单独的问题-您可以正确安装clang.和 -另一个单独的问题-如果需要,您可以将C :: B配置为使用clang进行构建.

Given that you are building your llvm program with GCC it is not clear why you want to install the clang compiler. Perhaps you want to use clang but you do not know that Code::Blocks can support the clang compiler, or do not know how to configure C::B to use clang. But let's take one thing at time. You can build this llvm program with gcc if you just get things set up properly. And - a separate issue - you can install clang properly. And - another separate issue - you can configure C::B to build with clang if you want.

Atropo粘贴的命令,用于安装最新的 clang及其调试器lldb.但是clang不需要所有的llvm库和 仅安装clang和lldb并不能为您提供所需的所有库 构建您的llvm程序.

Atropo pasted commands for installing the latest clang and its debugger lldb. But clang doesn't need all the llvm libraries and installing just clang and lldb does not give you all the libraries you need to build your llvm program.

您在评论之一中说,您已经能够构建程序 在终端中使用clang ++.这表明您当时已经在工作 手动安装clang和llvm.但我不知道你是否还有一个 中间的混乱,无论如何,我同意手动的Atropo 安装如此复杂的软件-自定义您的PATHLD_LIBRARY_PATH 等等-比通过软件包进行托管安装更不明智 虚假的说法,让程序包管理器正确处理.

You said in one of your comments that you had been able to build your program with clang++ in a terminal. That suggests you had, at that point, a working manual install of clang and llvm. But I don't know if you still have one after the intervening messing about and anyway I agree with Atropo that manually installing such complex software - customizing your PATH and LD_LIBRARY_PATH etc. etc. - is much less sensible than a managed installation from a package repoository, letting the package manager get things right.

首先,让我们在C :: B中使用gcc构建您的llvm程序,为此,首先 可能需要或可能不需要的预防步骤:

First, let's build your llvm program with gcc in C::B, and for that, begin with some precautionary steps that may or may not be necessary:

  • 撤消所做的所有自定义操作,然后手动删除或隐藏 已安装的clang/llvm二进制文件.

  • Undo all that customizing you did and delete or conceal your manually installed clang/llvm binaries.

获取所有软件包的最新信息.在控制台中,运行:

Get all your packages up to date. In a console, run:

sudo apt-get update

确保您具有用于构建C/C ++软件的所有基本软件包.在里面 控制台,运行:

Ensure you have all the basic packages for building C/C++ software. In the console, run:

sudo apt-get install build-essential

完成了预防措施.下一个:

That finishes the precautions. Next:

  • 从标准ubuntu 12.04存储库安装llvm.你会变老 一个,v2.9,但现在还可以:

  • Install llvm from the standard ubuntu 12.04 repository. You'll get an old one, v2.9 but that's fine for now:

sudo apt-get install llvm

现在,您已经拥有所需的所有软件.随身携带该控制台并启动 C :: B在您的简单llvm项目中.

Now you've got all the software you need. Keep that console handy and launch C::B in your simple llvm project.

  • 由于您现在具有标准的llvm系统安装,因此请更改后两个 您的源代码的#include指令如下:

  • As you now have a standard system-install of llvm, change the second two #include directives of your source code to the following:

#include <llvm/Module.h>

#include <llvm/LLVMContext.h>

获取llvm以告诉您需要将哪些编译器选项传递给GCC.在里面 控制台运行:

Get llvm to tell you what compiler options you need to pass to GCC. In the console run:

llvm-config --cxxflags

将该命令的输出从控制台复制到剪贴板.在C :: B中, 打开项目的构建选项并导航编译器设置-> 其他选项 对于GCC.在其他选项编辑框中,从 剪贴板,然后确定.

Copy the output of that command from the console to the clipboard. In C::B, open your project's Build options and navigate Compiler settings -> Other options for GCC. In the Other options edit-box, paste in the compiler options from the clipboard and OK it.

获取llvm以告诉您需要链接的库.在里面 控制台运行:

Get llvm to tell you what libraries you need to link. In the console run:

llvm-config --libs

将该命令的输出从控制台复制到剪贴板(这次 有很多).在C :: B中,导航构建选项-> 链接器设置-> 其他链接器选项. 在编辑框中,从剪贴板粘贴库选项,然后单击确定.

Copy the output of that command from the console to the clipboard (this time there is a lot of it). In C::B, navigate Build options -> Linker settings -> Other linker options. In the edit-box, paste in the library options from the clipboard and OK it.

获取llvm来告诉您需要将哪些(其他)选项传递给链接器.在里面 控制台运行:

Get llvm to tell you what (other) options you need to pass to the linker. In the console run:

llvm-config --ldflags

将该命令的输出从控制台复制到剪贴板.在C :: B中, 再次导航构建选项-> 链接器设置-> 其他链接器选项 在编辑框中,之后-重复,之后-您先前粘贴在此处的库选项, 从剪贴板粘贴其他链接器选项,然后单击确定.

Copy the output of that command from the console to the clipboard. In C::B, navigate, once again, Build options -> Linker settings -> Other linker options In the edit-box, after - repeat, after - the library options you have previously pasted there, paste in the additional linker options from the clipboard and OK it.

现在重建您的项目,这一次它将仅编译和链接 仅对未使用的变量c发出警告(至少对我有用).

Now rebuild your project and this time it will compile and link with only only a warning for the unused variable c (at least it does for me).

这涉及构建程序.如果现在运行它,它将输出从不打印", 我想你不想这么做;但这对您来说是个问题:)它可以生成并运行.

That covers building your program. If you now run it, it will output "Never printed", which I guess you don't want it to; but that's a problem for you :) It builds and runs.

如果您还想安装所有最新的llvm和clang软件包,请继续阅读.

If you also want to install all the latest llvm and clang packages, read on.

  • 在软件源中安装适用于Ubuntu 12.04的llvm工具链存储库

  • Install the llvm toolchain repository, for Ubuntu 12.04, in your software sources

sudo add-apt-repository 'deb http://llvm.org/apt/precise/ llvm-toolchain-precise main'

安装该存储库的gpg密钥以验证从中下载的软件包. 注意 此命令行上的最后一个连字符:

Install the gpg key of that repository to authenticate package downloads from it. Note the final hyphen on this commandline:

wget -O - http://llvm.org/apt/llvm-snapshot.gpg.key|sudo apt-key add -

再次刷新您的软件包数据库:

Refresh your package database again:

sudo apt-get update

安装整个llvm + clang工具链:

Install the whole llvm+clang toolchain:

sudo apt-get install clang-3.4 clang-3.4-doc libclang-common-3.4-dev libclang-3.4-dev libclang1-3.4 libclang1-3.4-dbg libllvm-3.4-ocaml-dev libllvm3.4 libllvm3.4-dbg lldb-3.4 llvm-3.4 llvm-3.4-dev llvm-3.4-doc llvm-3.4-examples llvm-3.4-runtime cpp11-migrate-3.4 clang-format-3.4

证明您有clang 3.4:

Prove that you have got clang 3.4:

clang -v

此命令应输出:

Ubuntu clang version 3.4-1~exp1 (trunk) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

最后,您可能需要配置C :: B以使用clang而不是GCC.我会 刚开始.

Finally, you might want to configure C::B to use clang instead of GCC. I will just get you started.

  • 在C :: B中,找到GCC的编译器设置,然后单击 Copy 按钮. 在添加新的编译器编辑框中,输入clang-3.4,然后单击确定.然后 遵循C :: B提示您更新工具链可执行文件"页面.
  • In C::B, navigate to Compiler settings for GCC and click the Copy button. In the Add new compiler edit-box, enter clang-3.4 and click OK. Then follow the prompt that C::B gives you to update the "Toolchain executables" page.

这篇关于如何安装clang预制二进制文件ubuntu 12.04的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆