I have an application which generally used the gcc optimization flag -O0 (no optimization). Now I have a file opt.c which I would like to compile with -O1, and leave rest of the files with -O0.
To be more specific, opt.c has a large for loop, which performs some simple arithmetic.
Finally only 1 executable is created which has all the files plus the opt.c. I am not sure if this causes any issue!
Changing this value will make the code compilation take more time and will use much more memory, especially as the level of optimization is increased. There are seven -O settings: -O0 , -O1 , -O2 , -O3 , -Os , -Og , and -Ofast .
GCC has a range of optimization levels, plus individual options to enable or disable particular optimizations. The overall compiler optimization level is controlled by the command line option -On, where n is the required optimization level, as follows: -O0 . (default).
In order to control compilation-time and compiler memory usage, and the trade-offs between speed and space for the resulting executable, GCC provides a range of general optimization levels, numbered from 0--3, as well as individual options for specific types of optimization.
GCC performs nearly all supported optimizations that do not involve a space-speed tradeoff. As compared to -O , this option increases both compilation time and the performance of the generated code.
Yes, that's absolutely fine. I'm curious why you don't wan't all of your code optimized? We typically optimize everything, except a few files where optimization causes problems.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With