1. 问题
// prog1.cc
#include <iostream>
int main()
{
std::cout << "Hello world" << std::endl;
return 0;
}
Mac上使用clang编译,
cc prog1.cc
会报错,
Undefined symbols for architecture x86_64:
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
...
std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> > std::__1::__pad_and_output<char, std::__1::char_traits<char> >(std::__1::ostreambuf_iterator<char, std::__1::char_traits<char> >, char const*, char const*, char const*, std::__1::ios_base&, char) in prog1-18ddb0.o
Dwarf Exception Unwind Info (__eh_frame) in prog1-18ddb0.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
2. 解决方案
(1)cc -lstdc++
$ cc -lstdc++ prog1.cc
$ ./a.out
Hello world
(2)clang++
$ clang++ prog1.cc
(3)g++
$ g++ prog1.cc