Difference between clang and clang++

Hi all,

If somebody would explain the difference between clang and clang++. I downloaded 2.9 release and clang.exe and clang++.exe are identical files?

Invoking the compiler as clang++ requests it to compile and link code as C++. This typically only matters when linking object files, where it causes the C++ standard library to be linked in.

I don't know why (or whether) these files are independent on disk; on Unix-y platforms, clang++ is just a symlink.

John.

They might be hard linked?

Sean

I had the impression that the Windows filesystem was sane enough to not allow hard-linking, but I am prepared to be corrected.

I rate it more likely that some packager just didn’t want to deal with symlinks.

John.

Driver activates C++ mode depending on executable name

Hard links are possible in NTFS, but the userland really doesn’t play well with them. They’re better avoided.

Soft links are also possible, but only since Vista have they become supported by the WinAPI properly. Many tools still won’t create them.

Sebastian

John McCall <rjmccall@apple.com> writes:

I had the impression that the Windows filesystem was sane enough to
not allow hard-linking, but I am prepared to be corrected.

http://en.wikipedia.org/wiki/Hard_link
"The Windows API from Windows 2000 onwards includes a CreateHardLink()
call to create hard links [...] Hard links require an NTFS partition."

It's probably more a matter of culture than technical limitation if
people use hardlinks more on Unix than on windows.

I had the impression that the Windows filesystem was sane enough to not
allow hard-linking, but I am prepared to be corrected.
I rate it more likely that some packager just didn't want to deal with
symlinks.

No "sane" links on windows. So, yes, one can consider "ln -s" as an
alias of "cp" there :slight_smile:

How can it do this if the files are identical? And if clang++ is only a symlink that would mean that one executable contains all the functionality? If this is the case, what is the reason behind two names?

Hello,

Driver activates C++ mode depending on executable name

How can it do this if the files are identical?

If clang is called via the symlink clang++, argv[0] is "clang++" instead of "clang". Look into
driver.cpp, function ParseProgName, where this is checked. There are quite a few supported names
(suffixes, actually).

And if clang++ is only a symlink that would mean that one executable contains all the functionality?

Yes :slight_smile:

If this is the case, what is the reason behind two names?

To activate C++ mode, just as Konstantin wrote.

Of course you can simply use "clang" to compile C++ code, too. You just have to pass "-x c++" and
"-lc++" (for libc++) or "-lstdc++" (for libstdc++) to it ("-x c++" is optional if the source file
is recognized (using its extension) as C++ code.

HTH,
Jonathan

Nikola Smiljanic <popizdeh@gmail.com> writes:

    Driver activates C++ mode depending on executable name

How can it do this if the files are identical?

int main(int argc, char **argv) {
  // argv[0] tells you.

clang is not the only one to do this kind of things. For example, on my
system, pdflatex is a symbolic link to latex, although they do different
things.

And if clang++ is only a symlink that would mean that one executable
contains all the functionality?

Sure.

If this is the case, what is the reason behind two names?

C++ is not a superset of C, so compiling C and C++ are different tasks,
although much of the C-compiling code can be re-used for C++.

Clang could as well have shipped one binary, and ask users to say
"clang" or "clang -x c++", but "clang++" is shorter to type.

A program can inspect the name by which it was called.

Sebastian

Driver activates C++ mode depending on executable name

How can it do this if the files are identical?

But argv[0] is not :slight_smile:

And if clang++ is only a symlink that would mean that one executable contains all thešfunctionality?

Right.

If this is the case, what is the reason behind two names?

For convenience and compatibility with compilers like gcc/g++.

Fantastic, I was wondering what was argv[0] good for, now I know. Thanks.

If clang is called via the symlink clang++, argv[0] is "clang++" instead of "clang". Look into
driver.cpp, function ParseProgName, where this is checked. There are quite a few supported names
(suffixes, actually).

Fantastic, I was wondering what was argv[0] good for, now I know. Thanks.

Someone should write a patch for clang so that when it is called as "WOPR", it lets you play a game
of Global Thermonuclear War.

Jonathan

If clang is called via the symlink clang++, argv[0] is "clang++" instead of "clang". Look into
driver.cpp, function ParseProgName, where this is checked. There are quite a few supported names
(suffixes, actually).

Fantastic, I was wondering what was argv[0] good for, now I know. Thanks.

Someone should write a patch for clang so that when it is called as "WOPR", it lets you play a game
of Global Thermonuclear War.

... and a patch for "tictactoe" to prevent the ensuing nuclear annihilation.

If we had "the big clang.dll (like --shared llvm.dll, not only C
API)", we could obtain smaller clang.exe and clang++.exe. Of course
they may be identical.

I love monolithic clang!

ps. Note that, gcc has its big cc1.exe and cc1plus.exe (and other
backends) in most platforms.

...Takumi

Someone tried, but seems not finished yet…

2011/6/1 NAKAMURA Takumi <geek4civic@gmail.com>