Passing C/C++ #defines to makefile

Mawg says reinstate Monica picture Mawg says reinstate Monica · Jan 11, 2010 · Viewed 39k times · Source

I develop C/C++ using the Eclipse IDE. Eclipse also generates a makefile which I don't want to edit as it will simply be overwritten.

I want to use that makefile for nightly build within Hudson.

How do I pass #defines which are made in the project file of the IDE to the makefile ? (and why doesn't Eclipse already include them in the generated makefile?)

I actually had this figured out once, then accidentally overwrote it :-( But at least I know that it can be done...

Answer

Scott Wales picture Scott Wales · Jan 21, 2010

If you are running make from the command line, use

make CPPFLAGS=-DFOO

which will add -DFOO to all compilations. See also CFLAGS, CXXFLAGS, LDFLAGS in the make manual.