Installed clang:

$~/Projects/clang$ sudo apt-get install clang
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 0 B/3,590 B of archives.
After this operation, 42.0 kB of additional disk space will be used.
Selecting previously unselected package clang.
(Reading database ... 259453 files and directories currently installed.)
Preparing to unpack .../clang_1%3a3.5-23ubuntu1_i386.deb ...
Unpacking clang (1:3.5-23ubuntu1) ...
Processing triggers for man-db ( ...
Setting up clang (1:3.5-23ubuntu1) ...

Compile code:

$~/Projects/clang$ clang hw.cpp
/tmp/hw-70de0d.o: In function `main':
hw.cpp:(.text+0x8): undefined reference to `std::cout'
hw.cpp:(.text+0x1a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/hw-70de0d.o: In function `__cxx_global_var_init':
hw.cpp:(.text.startup+0x10): undefined reference to `std::ios_base::Init::Init()'
hw.cpp:(.text.startup+0x16): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Source code:

int main()

What else is needed to use clang?

  • 2
    Looks like a linker error: you need to link against the C++ libraries. Does clang know that this is c++ code? Commented Feb 19, 2015 at 23:10

1 Answer 1


You need to use clang++. clang is the C compiler, clang++ is the C++ compiler. Like gcc. I think these are basically the same compiler under the hood, but (again like gcc), clang++ links against the C++ libraries by default, while clang doesn't. Hence the linker errors.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .