Search code examples
c++optimizationg++cygwin

Increasing Optimization Level g++


I'm trying to compile a relatively simple c++ program using cygwin and g++. I can compile it using the following command:

g++ -o main main.cpp -lgmpxx -lgmp

(note: the last two reflect the inclusion of the gmp libraries).

I'd like to increase the level of optimization that this is compiled with. I thought that I could just change this command line to:

g++ -o3 main main.cpp -lgmpxx -lgmp

but this totally blows up. I get about two full screens of error messages.

How can I increase the optimization here? Thanks!


Solution

  • That should be -O3, not -o3. Otherwise you're telling g++ to put the compiled executable into a file named 3, and you're feeding it main, your previously-compiled executable, as input. It's probably trying to interpret that as source code, hence the errors.