Ask Your Question
0

COCALC c++ clang Errors

asked 2018-11-16 20:44:33 +0200

thetha gravatar image

updated 2018-11-16 22:27:50 +0200

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...

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-11-16 22:58:28 +0200

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
edit flag offensive delete link more

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: 2018-11-16 20:44:33 +0200

Seen: 136 times

Last updated: Nov 16 '18