clang cannot find standard template library

Hi.

Looking for an alternative to g++, I have stumbled across
clang. And, impressively, clang has managed to compile my
C++ code consisting of some 80 000 lines of code.

However, when it comes to linking, things stop. It seems
that clang does not find the standard template library.

As a matter of fact, even the trivial

#include <iostream>
int main () { std::cout << "Hello world." << std::endl; }

ends it's compilation with the following error message:

nebuchadnezzar:/opt/project/Cohiba/trunk/cohiba/tmp$ clang test.cpp
/tmp/cc-jpZ3sj.o: In function `__cxx_global_var_init':
test.cpp:(.text+0x18): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text+0x20): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc-jpZ3sj.o: In function `main':
test.cpp:(.text+0x63): undefined reference to `std::cout'

[snip]

Can anyone give me a hint where to look? I have tried
the manual pages, but that didn't bring me any further.

By the way, I'm using the clang provided bu Ubuntu 10.04

Best regards
Pål

Pål Dahle <pal.dahle-+dScP4IL3Ug@public.gmane.org> writes:

[...]

nebuchadnezzar:/opt/project/Cohiba/trunk/cohiba/tmp$ clang test.cpp

Try

  clang++ test.cpp

[...]

Use clang++ instead of clang (although this is a symlink on clang, the driver detect that it was invoked using a command containing ++ and switch to c++ mode).

-- Jean-Daniel

Thanks for your reply. Unfortunately this didn't help.

nebuchadnezzar:~$ clang++
clang++: command not found
nebuchadnezzar:~$ apt-cache search clang++
clang - Low-Level Virtual Machine (LLVM), C language family frontend

Anyway, I found a solution online

clang -emit-llvm -c file.c && llvm-ld file.o

So I am supposed to use llvm-ld for linking and not clang.

Thanks again
Pål

Uh no. You really want clang++. I don't know what's wrong with your
package, but if you download and compile the sources from llvm.org
you'll have a clang++.

-eric

Pål Dahle <pal.dahle-+dScP4IL3Ug@public.gmane.org> writes:

[...]

Thanks for your reply. Unfortunately this didn't help.

nebuchadnezzar:~$ clang++
clang++: command not found
nebuchadnezzar:~$ apt-cache search clang++
clang - Low-Level Virtual Machine (LLVM), C language family frontend

It appears that things have changed since the Debian package was
produced, yes.

Pål Dahle<pal.dahle-+dScP4IL3Ug@public.gmane.org> writes:

[...]

Thanks for your reply. Unfortunately this didn't help.

nebuchadnezzar:~$ clang++
clang++: command not found
nebuchadnezzar:~$ apt-cache search clang++
clang - Low-Level Virtual Machine (LLVM), C language family frontend

It appears that things have changed since the Debian package was
produced, yes.

As far as I know, Ubuntu removed the clang++ symlink (for whatever reason, maybe because clang++ was still in alpha that time). You just need to create a symlink called clang++ to the clang executable in your path to get clang++, though.
Cornelius

Creating the symlink made the 'hello world' code both compile and
run. My real code also seemed to be linked nicely, but the invokation
endeed with a:

nebuchadnezzar:$ ./cohiba
unexpected reloc type in static binarySegmentation fault

A quoted google search for this error message gives a total of
one hits. I guess this is it...

Thanks for all help
Pål

Pål Dahle <pal.dahle-+dScP4IL3Ug@public.gmane.org> writes:

[...]

nebuchadnezzar:$ ./cohiba
unexpected reloc type in static binarySegmentation fault

A quoted google search for this error message gives a total of
one hits. I guess this is it...

C++ support has really improved a lot (IME) in the last couple of
weeks.