When I build a Release C++ project in NetBeans, it automatically configures it with the -O2 option.
I don't see anywhere in the compiler options where I can override this value. I know it's set to -O2 because I can see the cmdlines it uses in the Build window: g++ -O2 ...
If I add -O1 into the "Additional Otions" within the compiler settings it doesn't honour it because the cmdline now becomes g++ -O1 -O2 ...
and so the -O2 supersedes my own setting.
So, where in the IDE can I set the -O optimization level compile setting?
I am using GNU compile tools on Linux if that makes any difference.
I finally found the solution by exploring a bit more. In the dialog from the OP there is the option, 'Development Mode' which is currently set to 'Release'. There are a number of options under there and each of those correspond to different optimization levels and/or debug output compile flags:
No Flags -c
Debug -c -g
Performance Debug -c -g -O
Test Coverage -g -c
Diagnosable Release -c -g -O2
Release -c -O2
Performance Release -c -O3
Although there doesn't seem to be an option for -O1, that's basically the intended way for you to select different optimization levels in NetBeans.
Please look at the nbproject/Makefile-Release.mk
file.
nekto@ubuntu:~/host/ex/dt-netbeans-samples-cpp-Welcome$ grep -r O2 *
nbproject/Makefile-Release.mk: $(COMPILE.cc) -O2 -MMD -MP -MF "[email protected]" -o ${OBJECTDIR}/welcome.o welcome.cc
It looks like the -O2
option presence in the Release
configuration is the default and unchangeable, however you always can create your own build configuration (and you did as I see).
Each build configuration has its own nbproject/Makefile-<configuration name>.mk
file, which contains following lines:
# CC Compiler Flags
CCFLAGS=-O1
CXXFLAGS=-O1
I've created a new configuration, made it active, and set the -O1
option above from the NetBeans properties pop-up window, C++ Compiler
-> Additional Options
, and my compilation line didn't contain the -O2
option. My Additional Options
panel is below:
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