Is it possible to compile files with different levels of gcc optimization for a single application?

I have an application that usually uses the gcc -O0 optimization flag (no optimization). Now I have an opt.c file that I would like to compile with -O1 and leave the rest of the files with -O0.

To be more specific, opt.c has a large for loop that does some simple arithmetic.

Finally, only 1 executable is created, which has all the files plus opt.c. I'm not sure if this causes any problems!

+5
source share
1 answer

Yes, that’s absolutely normal. I wonder why you did not optimize all your code? Usually we optimize everything except a few files in which optimization causes problems.

+6
source

Source: https://habr.com/ru/post/1245644/


All Articles