簡體   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