0
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. Why does this happen?

  • 4
    On the Mac, `gcc` is sometimes an alias for `clang`, rather than the actual GCC. What do you get when you run `gcc --version`? – jjramsey Dec 02 '21 at 18:43
  • Oh, no. It is clang. But the same warning occurs even if i use `-std=c++17` or `-std=gnu++17` – RasanMeasyKZ Dec 02 '21 at 18:46
  • 1
    Beside the fact that `gcc` is likely `clang` on Mac, why do you set optimization level in the code? This is usually counterproductive. Why don't set optimization level as part of your build system? – SergeyA Dec 02 '21 at 18:46
  • It's all for competitive programming – RasanMeasyKZ Dec 02 '21 at 18:46
  • You should not enable optimizations inside your code even for competitive programming. Build system takes care of that. – SergeyA Dec 02 '21 at 18:55
  • I liked when OP thought setting the C++ standard would help clang use gcc intrinsics. – sweenish Dec 02 '21 at 19:07
  • `Oh, no. It is clang` Please post the exact version output of the compiler that you use, be it `gcc --version` or `clang --version`. – KamilCuk Dec 02 '21 at 19:22
  • On macos `gcc --version` outputs `AppleClang` – Guillaume Racicot Dec 02 '21 at 19:22
  • 1
    Does this answer your question? [Apple LLVM 5.0 pragma optimize](https://stackoverflow.com/questions/19768895/apple-llvm-5-0-pragma-optimize) – static_cast Dec 02 '21 at 19:45

1 Answers1

0

The problem was that g++ is a clang alias in MacOS by default So i did this

cd /usr/local/bin
ln -s g++-11 g++

this fixes the problem and g++ command will run actual gcc compuler instead of clang