3
votes

I installed clang to compare its use with g++ (gcc) for some C++ programs; 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).

At one point, I needed to install the LLVM libraries (v. 2.9.), while before I had only downloaded clang. Subsequent to this, compilation with clang++ doesn't seem to work for the following tutorial code; while g++ appears to work with LLVM directives (e.g., 'llvm-config --libs`, etc.). 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. (suggesting g++ syntax), as the library include locations had changed.

My questions to explain the changes after downloading the llvm libs:

(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? If yes, how can I make sure that I actually use gcc, not clang, when I want to?

(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? (c., eg, here)

My System:

Ubuntu 12.04.
llvm 2.9.
gcc 4.6.3.
clang 3.0.

1
Can you try running the commands which g++ and g++ --version - andypea
As far as I know clang does not do anything with existing gcc executables. The LLVM tutorial you linked could use any C++ compiler so I'm guessing they switched to gcc because your average person is more likely to have gcc than they are to have clang. - David Brown
@vonbrand: I typed 'llvm' in the software manager. Developer libraries popped, which I installed. Where I can arrange for it, I prefer to integrate my installs in the software mgr. - gnometorule
@Andrew.punnett: will do in the morning when back at comp. - gnometorule
It's not aliased, and confirming with which etc, it still points to gcc. - gnometorule

1 Answers

1
votes

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++'.

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)

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!

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?