【发布时间】:2014-05-28 17:37:26
【问题描述】:
我正在使用 Xcode 5.1.1 运行 MacOS X Mavericks,包括命令行工具。 我正在使用 Xcode 提供的 clang++ 编译简单的 C++ 程序,版本信息是: Apple LLVM 5.1 版 (clang-503.0.40)(基于 LLVM 3.4svn)
我发现如果我尝试运行以下命令
clang++ -o hello.out hello.cpp
我收到以下错误:
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in hello-2ad0da.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in hello-2ad0da.o
"std::cout", referenced from:
_main in hello-2ad0da.o
"std::basic_ostream<char, std::char_traits<char> >& std::operator<<<std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:
_main in hello-2ad0da.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果我将命令更改为
clang++ -o hello.out -stdlib=libstdc++ hello.cpp
我没有收到任何错误。
有没有办法让“-stdlib=libstdc++”成为 clang++ 的默认值,无论是配置设置还是环境变量?另外,仅供参考,为什么我会收到错误消息?
【问题讨论】:
-
这只是一个简单的 C++ 程序来打印“Hello, World”。如果您愿意,我可以发布源代码,但请注意,如果我指定 stdlibc++,它会起作用。它包含的唯一库是