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?
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
Related
If the compiler has some command-line flags and the code has some pragmas that are incompatible with those flags, which one will be used?
To be clearer: I am compiling with g++ -g -O2 -std=gnu++17 -static {files} – GCC version g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0.
If I write in my code #pragma GCC optimize("Ofast"), will the final code be compiled with -O2 or with -Ofast?
That depends on if it's above or below the pragma.
void this_will_be_compiled_with_O2() { stuff(); }
#pragma GCC optimize("Ofast")
void this_will_be_compiled_with_Ofast() { stuff(); }
Although not explicitly mentioned in the documentation, the description of the #pragma GCC reset_options directive implies that any #pragma GCC optimize directive will override the command line option(s):
#pragma GCC reset_options
This pragma clears the current #pragma GCC target and #pragma GCC optimize to use the default switches as specified on the command line.
is that possible that g++ somehow compile my program with older standard than I specified?
I compile with:
g++ -Wall -Wextra -pedantic -O3 -std=c++2a -fconcepts
And compiler can't recognize bind_front function ( I included <functional> ). Compiler version is GCC 8.3.
GCC 8.3 does not support std::bind_front. Check here.
You need to use GCC 9.1 or 9.2. Check here.
How to install GCC 9?
UPDATE
As the #walnut's comment says, there is a g++ 9 package in the standard repositories since Ubuntu 19.04.
I'm trying to configure eclipise kepler to use c++ 11.
I appended -std=c++11 to:
Properties > c/c++ build > settings > GCC c++ complier > Miscellaneous>other flags
But when I compile the project it says:
compilation terminated. /bin/sh: 1: -std=c++11: not found
I'm using gcc on ubuntu,
any ideas?
Flags (or compiler options) are nothing but ordinary command line arguments passed to the compiler executable.
Assuming you are invoking g++ from the command line (terminal):
$ g++ -Wall -g -std=c++11 your_file.cpp -o your_program
or
$ g++ -Wall -g -std=c++0x your_file.cpp -o your_program
if the above doesn't work.
So in your case if -std=c++11 does not work, try -std=c++0x
Another source for this error could be an old compiler version.
Type gcc --version into the terminal and check the version. Here is a quick overview which version is capable of c++11:
C++11 Support in GCC
GCC 4.8.1 was the first feature-complete implementation of the 2011
C++ standard, previously known as C++0x.
This mode can be selected with the -std=c++11 command-line flag, or
-std=gnu++11 to enable GNU extensions as well.
Link: https://gcc.gnu.org/projects/cxx-status.html
I'm taking part in a programming contest and the requirement is that code will be compiled using following command:
g++ -std=c++11 -O2 -o a.out orienteering.cpp
How do I check if my code works for this command? (I use DevC++ for coding and it has automatic compilation).
Also compiler should be GCC 4.8.2 or later. What does this mean? Is my older GCC version (4.7.2) not suitable?
You check your code by placing it in a file named orienteering.cpp, and running this command in the same directory:
g++ -std=c++11 -O2 -o a.out orienteering.cpp
If the compiler spits out any messages at all then you have a problem. If the compiler is silent and creates a file named a.out, then all is well.
GCC 4.7.2 does not meet the criteria "GCC 4.8.2 or later".
I'm trying to compile and strip a very simple programm in C++ with the g++ compiler (4.6.0 on Mac OSX). But while compiling i get an warning.
source code:
#include </usr/local/Cellar/gcc/4.6.0/gcc/include/c++/4.6.0/iostream>
int main(){
std::cout << ("Hello World\n") ;
}
Terminal code:
g++ hello.cc -Wall -std=c++0x -s
/* or an alternative: */
g++ hello.cc -Wall -std=c++0x -o test -Wl,-s
Compiler warning:
ld: warning: option -s is obsolete and being ignored
Somebody any idea's about this weird warning?
Edit:
The weird thing is the size does decrease when using the -s flag, the decreases from 9,216 bytes to 9,008.
However when i use the following the size decreases to 8,896 bytes.
cp hello hello_stripped
strip hello_stripped
The error message is from ld, not from gcc or g++. (The gcc and g++ commands are a drivers that invokes the compiler, the linker, and other tools.)
gcc passes the -s option to the linker, as documented in the gcc 4.6.1 manual; apparently the MacOS port of gcc still does that.
The GNU linker (GNU ld) still accepts the -s option with its usual meaning. But the MacOS linker (also called ld) ignores it, as documented in the MacOS ld manual:
-s Completely strip the output, including removing the symbol table.
This file format variant is no longer supported. This option is
obsolete.
And the MacOS gcc manual, unlike GNU's gcc manual, doesn't mention "-s".
Apparently the -s flag is obsolete. You can use the strip program instead though.