繁体   English   中英

MacOS 上的 c++11 警告

[英]c++11 warning on MacOS

我的 Mac 上有 clang 13.0.0。 我正在尝试使用命令编译一些.cpp文件

g++ file.cpp -o file

但我收到此警告消息:

file.cpp:23:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const double &e : timestamp) outFile << std::setprecision(10) << e << "\n";

On the clang documentation is said that c++11 is supported by clang 13. On my terminal running man clang I find: The default C++ language standard is gnu++14 .

输入g++ -v我得到:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

为什么我会收到此警告?

AppleClang默认为c++98,而llvm-clang默认为后面的gnu++14; 要访问 c++11 实现,您必须添加标志--std=c++11--std=c++14 参看。 https://opensource.apple.com/source/clang/clang-703.0.29/src/tools/clang/www/cxx_status.html

If you are expecting the gnu g++ , it must be installed separately, because on macOS g++ aliases to clang , which is the Apple fork of clang known as AppleClang .

如果您期待llvm-clang ,那也必须单独安装。 AppleClang 13 ≠ llvm-clang 13。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM