Question

The following Hello World program compiles inside Xcode, but not when compiled with via clang in the Terminal:

#include <iostream>
int main()
{
  std::cout << "Hello World!";
}

specifically, the command i'm using is:

clang c++test.cpp

where c++test is the name of the file. This produces a bunch of gibberish errors like:

(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*,     
char const*, std::__1::ios_base&, char) in c++test-497cf6.o

As well as this:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I checked and the c++ libs appear present on the system, so I'm pretty sure I'm doing something work. Is there a -framework I need to link to?

Was it helpful?

Solution

If you compile/link C++, use (clan)g++. This will ensure the C++ standard library is also linked in.

Alternatively, add -lstdc++ or in your case -lc++ to the link command. I would just call clang++ though.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top