gpt4 book ai didi

c++ - 使用启用了 c++11 的 clang 进行编译失败

转载 作者:太空宇宙 更新时间:2023-11-04 16:21:13 25 4
gpt4 key购买 nike

具有以下test.cpp:

#include <iostream>
int main() {
int a{};
std::cout << "TEST" << std::endl;
}

当使用最新的 GCC (4.8.0) g++ test.cpp -std=c++11 构建时(gcc 也失败),文件编译。尝试用最新的 clang 编译

clang version 3.4 (trunk 182322)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

构建失败:

clang test.cpp -std=c++11 

Undefined symbols for architecture x86_64:
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
_main in test-NcubkF.o
"std::ios_base::Init::Init()", referenced from:
___cxx_global_var_init in test-NcubkF.o
"std::ios_base::Init::~Init()", referenced from:
___cxx_global_var_init in test-NcubkF.o
"std::cout", referenced from:
_main in test-NcubkF.o
"std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
_main in test-NcubkF.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 test-NcubkF.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(或 gcc)在 C++11 模式下工作可以做什么?

最佳答案

clang 适用于 C。对于 C++,请使用 clang++

clang++ test.cpp -std=c++11

关于c++ - 使用启用了 c++11 的 clang 进行编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16660854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com