Is there a way to make a c++ compiler flag as default

949 Views Asked by At

Just like we specify input flags in the settings of the project in Xcode

Can I make few flags like -O3 or -fopenmp as default flags in command line when I use Terminal.
So that I dont have to type them everytime I compile some c++ fies. Is there a file in the installed gcc or C++ that I can edit to make them default. Please let me know thanks

1

There are 1 best solutions below

0
On

For situations like this you'd probably use a makefile if it's project specific (or other similar automated build management like scons or cmake).

If you want it always on the terminal, you can alias your command to always specify those options, i.e.

alias g++='g++ -O3 -fopenmp'

Note that you said 'terminal' so I assume this is a type of *nix. If that is the case you can also set this into your terminal profile, like ~/.bashrc if you use bash, or ~/.zshrc if you use zsh, etc.