-2

I want to add some flags per default, so as not to type them at each compilation.

is there any way to add compile flags per default ?

Like optimisation flags or whatever. I found a solution with alias, but i dont know if its a good way, if u have better ideas !

  • 5
    A makefile perhaps? – πάντα ῥεῖ Jul 15 '22 at 09:30
  • @πάνταῥεῖ No i really want a solution without makefiles, in shell, something per default like -std=c++... you got me ? –  Jul 15 '22 at 09:33
  • Put your flags into a environment variable, and reference it. – πάντα ῥεῖ Jul 15 '22 at 09:37
  • As soon as you get more complicated multi-file projects, shell commands and scripts will be too much work. I'd recommend you learn the build-tools available in your environment, or perhaps even learn how to use an IDE (which will help with much more than just building your projects correctly). – Some programmer dude Jul 15 '22 at 10:37
  • I'm afraid there are no magic buttons to push that will make things happen the way everyone likes them to happen. C++ is just too complicated. The proper and the simplest way to implement this is with a Makefile. – Sam Varshavchik Jul 15 '22 at 11:02

1 Answers1

1

Create a Makefile with the following contents:

CXXFLAGS += -std=c++17 -O2

Now you can type make foo to compile foo.cpp with the defaults flags in your Makefile.

Botje
  • 26,269
  • 3
  • 31
  • 41