Increasing Optimization Level g++

Go To StackoverFlow.com

2

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!

2012-04-05 01:32
by Alex
What are the error messages - Timothy Jones 2012-04-05 01:33


9

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.

2012-04-05 01:34
by Wyzard


10

Options are case sensitive: the -o option allows you to specify the name of the output file, -O sets the amount of optimisation, so you want:

g++ -O3 -o main main.cpp -lgmpxx -lgmp
2012-04-05 01:35
by huon
Thank you. Didn't realize that there was any case sensitivity - Alex 2012-04-05 01:40
Ads