[英]Unknown GCC pragmas on Mac
warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma GCC optimize("O3")
I want to enable GCC optimization flags, but they are ignored when i'm compiling code, although they are present in documentation .我想启用 GCC 优化标志,但在我编译代码时它们被忽略了,尽管它们存在于文档中。 Why does this happen?
为什么会这样?
The problem was that g++ is a clang alias in MacOS by default So i did this问题是 g++ 默认情况下是 MacOS 中的 clang 别名所以我这样做了
cd /usr/local/bin
ln -s g++-11 g++
this fixes the problem and g++ command will run actual gcc compuler instead of clang这解决了问题,g++ 命令将运行实际的 gcc 编译器而不是 clang
In summary, the most commonly used optimization flags are these:总之,最常用的优化标志是这些:
-O0
for no optimization; -O0
不优化; -O1
for a few optimizations; -O1
进行一些优化; -O2
for lots of optimizations; -O2
进行大量优化; -O3
for all of the O2 optimizations plus some other expensive ones; -O3
用于所有 O2 优化以及其他一些昂贵的优化; -Os
the same as O2 plus a few optimizations for reducing the size of the binary; -Os
与 O2 相同,加上一些优化以减小二进制文件的大小; -flto
for usually expensive link-time optimizations. -flto
用于通常昂贵的链接时间优化。
In GCC, you might write something like g++ -std=c++20 -Wall -O3 sourcefilename.cpp -o myprogram
.在 GCC 中,您可能会编写类似
g++ -std=c++20 -Wall -O3 sourcefilename.cpp -o myprogram
的内容。
Check these links too:也检查这些链接:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89038 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89038
Suppress -Wunknown-pragmas warning in GCC 抑制 GCC 中的 -Wunknown-pragmas 警告
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.