How do I add conditional compilation to my makefile: say if I have a #ifdef SAVE_DATA
in a cpp (.cc) file.
views:
187answers:
2
+3
A:
For gcc
et al, you can use the -Dfoo
flag to define foo
:
g++ -DSAVE_DATA=1 -c foo.cpp
Dirk Eddelbuettel
2009-12-05 00:59:38
Note that modifying CXXFLAGS is how you pass options to the C++ compiler in make.
Roger Pate
2009-12-05 01:20:17
Yes that is one of many possibilities, but you can also use it implicitly as argument to the command ultimately using as I did here.
Dirk Eddelbuettel
2009-12-05 01:47:34
I tend to do both: if I define a custom rule for particular cpp files, I write it as `$(CXX) $(CPPFLAGS) $(CXXFLAGS) -special -flags -c -o $@ $<`. Or sometimes with the special flags before CXXFLAGS, it's kind of the same issue as !important in CSS.
Steve Jessop
2009-12-05 02:21:03
Of course you can use target-specific variables, but in my experience they cause more confusion than they save. Maybe I should have stuck with them longer.
Steve Jessop
2009-12-05 02:26:50