Ask Your Question
0

COCALC c++ clang Errors

asked 6 years ago

thetha gravatar image

updated 6 years ago

Whatever this means:

/WEEK1$ g++  hello.cpp
/WEEK1$ clang hello.cpp
/tmp/hello-e918fc.o: In function `main':
hello.cpp:(.text+0xa): undefined reference to `std::cout'
hello.cpp:(.text+0x24): 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/hello-e918fc.o: In function `__cxx_global_var_init':
hello.cpp:(.text.startup+0x13): undefined reference to `std::ios_base::Init::Init()'
hello.cpp:(.text.startup+0x19): undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
~/WEEK1$ g++  hello.cpp -o hello
~/WEEK1$ ./hello
Hello World~/WEEK '

g++ complier works clang compiler not

https://share.cocalc.com/share/a8d047...

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 6 years ago

rburing gravatar image

You're using the wrong syntax to compile C++ code with clang. It should be:

clang++ -o hello hello.cpp

Or, if you really wish to use clang directly instead of clang++, something like:

clang -x c++ -lstdc++ -o hello hello.cpp
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 6 years ago

Seen: 733 times

Last updated: Nov 16 '18