Domanda

Using GCC to compile C++ code: there's a big list of options (warnings, optimisations etc) I want to always compile with. It's tiresome to keep pasting them into the command line. Can I do something like

g++ test.cpp -o test.o -myoptions

where "-myoptions" would enable a list of options like

-pedantic
-Wall
-O2
-Wshadow
-...

that I've defined somewhere?

I've tried searching but couldn't find a guide for this. Is it possible or do I have to use make files? System is windows 7 if that's relevant. Thanks


edit: in case someone searches for this in the future, windows specific answer: go to control panel -> system -> advanced system settings -> environment variables, create new system variable named "myoptions" and value "-option1 -option2 -option3 ...". Then compile with "g++ test.cpp -o test.o %myoptions%"

È stato utile?

Soluzione

You can set an environment variable:

export CXXFLAGS="-Wall -O3 -std=c++11"

and use

g++ $CXXFLAGS test.cc -o test

Note that some variables are more-or-less standardized and when you set them, several build system will automatically use them. Among others, google for CFLAGS, CPPFLAGS, CXXFLAGS, ...

Here's also a starting point on SO.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top