简体   繁体   English

Clang,LLVM和g ++

[英]Clang, LLVM, and g++

I installed clang to compare its use with g++ (gcc) for some C++ programs; 我安装了clang来比较它与g ++(gcc)在一些C ++程序中的使用; as in, I compared compilation time, error feedback, etc,. 在中,我比较了编译时间,错误反馈等。 for the same programs. 对于相同的程序。 I did this mainly for the official LLVM tutorial (implementing a compiler using LLVM). 我这样做主要是为了官方LLVM教程(使用LLVM实现编译器)。

At one point, I needed to install the LLVM libraries (v. 2.9.), while before I had only downloaded clang. 有一次,在我只下载clang之前,我需要安装LLVM库(v.2.9。)。 Subsequent to this, compilation with clang++ doesn't seem to work for the following tutorial code; 在此之后,使用clang ++进行编译似乎不适用于以下教程代码; while g++ appears to work with LLVM directives (eg, 'llvm-config --libs`, etc.). 而g ++似乎与LLVM指令一起使用(例如,'llvm-config --libs`等)。 Concurrent to installation of the libraries, I had to also go from the old tutorial I was reading (llvm 2.2., suggesting clang++ syntax), to one for 3.0. 在安装库的同时,我还必须从我正在阅读的旧教程(llvm 2.2。,建议使用clang ++语法)到3.0。 (suggesting g++ syntax), as the library include locations had changed. (建议g ++语法),因为库包含的位置已经改变。

My questions to explain the changes after downloading the llvm libs: 在下载llvm库后解释更改的问题

(1) When I now type 'g++', am I still actually working with gcc, or has llvm/clang set itself as a new default mimicking the gcc syntax? (1)当我现在输入'g ++'时,我是否还在使用gcc,或者llvm / clang将自己设置为模仿gcc语法的新默认值? If yes, how can I make sure that I actually use gcc, not clang, when I want to? 如果是的话,我怎么能确保在我想要的时候实际使用gcc而不是clang?

(2) If g++ still is gcc, any opinions/guesses why the official clang/llvm tutorial switches from suggesting the use of its own competing compiler back to gcc? (2)如果g ++仍然是gcc,那么任何意见/猜测官方clang / llvm教程为什么会从使用自己的竞争编译器回到gcc? (c., eg, here ) (例如, 在这里

My System: 我的系统:

Ubuntu 12.04. Ubuntu 12.04。
llvm 2.9. llvm 2.9。
gcc 4.6.3. gcc 4.6.3。
clang 3.0. 铿锵3.0。

In order for typing g++ to execute a clang compiler, you'd probably be looking at either a symbolic link called g++ to clang, earlier in your $PATH than the path to the real g++ , or else an alias named g++ , along the lines of alias g++='clang++' . 为了输入g++来执行clang编译器,你可能会看到一个名为g++ to clang的符号链接,早于$PATH不是实际g++的路径,或者是一个名为g++的别名,沿着这些行alias g++='clang++'

You can check for the alias (although I imagine it's unlikely) by typing alias g++ , which will let you know if you have any alias set up (and if so, what to) 您可以通过键入alias g++来检查别名(虽然我认为这不太可能),如果您设置了任何别名,可以通知您(如果是,那么该怎么做)

In order to change the $PATH issue, if it occurs, you'd have to either remove the symbolic link (seems sensible, given if you wanted clang , you could just type clang++ instead of g++ ) or change the position of the symbolic link in the PATH variable, but since they're likely to exist in /usr/local/bin or something similar, that would render a symbolic link unlikely too! 为了改变$PATH问题,如果它发生了,你必须删除符号链接(似乎是明智的,如果你想要clang ,你可以只输入clang++而不是g++ )或改变符号链接的位置在PATH变量中,但由于它们可能存在于/usr/local/bin或类似的东西中,因此也不太可能呈现符号链接!

Given this, probably g++ still calls the gcc g++ compiler, and someone was just a little careless when typing the tutorial - I see only the one mention of g++ on the page you linked, near the bottom? 考虑到这一点,可能g++仍然会调用gcc g++编译器,在编写教程时有人只是有点粗心 - 我只看到你链接的页面上提到的g++ ,靠近底部?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM