How to use clang

I read about clang in the lounge last night and I figured I would try it out, I'm on a Linux (Fedora) and I did 'yum install clang'. It seems like it installed fine, it installed these two packages;

clang-3.3-4.fc19.x86_64
llvm-3.3-4.fc19.x86_64

But now when I tried to use 'clang test.cpp' it threw over a hundred errors and failed while g++ plugged along just fine on the same file...
When I did 'clang -c test.cpp' it did run through all the way to the linker phase without issues. It created a file named test.o which I then did 'g++ test.o' and it finally became an executable "a.out".

I read the man page on clang and it sounds like typing 'clang filename.cpp' should have made an executable without issues.

Am I missing a step?

test.cpp;
1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
using namespace std;

int main()
{
        string hi = "Hello world";
        cout << hi;
}


[newbieg@localhost c++]$ clang test.cpp
Errors;
/tmp/test-SlWm4X.o: In function `main':
test.cpp:(.text+0x14): undefined reference to `std::allocator<char>::allocator()'
test.cpp:(.text+0x26): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
test.cpp:(.text+0x34): undefined reference to `std::allocator<char>::~allocator()'
test.cpp:(.text+0x3d): undefined reference to `std::cout'
test.cpp:(.text+0x42): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
test.cpp:(.text+0x54): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
test.cpp:(.text+0x71): undefined reference to `std::allocator<char>::~allocator()'
test.cpp:(.text+0x88): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
/tmp/test-SlWm4X.o: In function `__cxx_global_var_init':
test.cpp:(.text.startup+0x11): undefined reference to `std::ios_base::Init::Init()'
test.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
/tmp/test-SlWm4X.o: In function `__clang_call_terminate':
test.cpp:(.text.__clang_call_terminate[__clang_call_terminate]+0x9): undefined reference to `__cxa_begin_catch'
test.cpp:(.text.__clang_call_terminate[__clang_call_terminate]+0x12): undefined reference to `std::terminate()'
/tmp/test-SlWm4X.o:(.eh_frame+0x47): undefined reference to `__gxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Last edited on
clang++
Just as there is gcc for C and g++ for C++, there is clang for C and clang++ for C++.
closed account (Dy7SLyTq)
does clang also work with obj-c?
http://clang.llvm.org/ - read literally the first sentence on the page ;)
closed account (Dy7SLyTq)
meh... i dont rtfm too much. its a bad habit. i also dont use clang too much
Topic archived. No new replies allowed.