views:

609

answers:

3

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...

+1  A: 

For GCC use -D define.

OP commented below that he wants to pass the define into make and have it pass it on to GCC.

Make does not allow this. Typically you just add another make rule to add defines. For instance 'make release' vs 'make debug'. As the makefile creator you make the two rules and have the defines right in the make file. Now if Eclipse is not putting the defines into the makefile for you, I would say Eclipse is broken.

gbrandt
One of us has answered the wrong question. I *think* he has a c++ header with some `#defines`, and wants to use them to make decisions in make. You suggestion is correct if he has some variables in make and wants to get them considered by the preprocessor during c++ compilation.
dmckee
Maybe I wasn't clear enough, sorry.I want to pass the #defines to make, which will then use them when calling gcc.So, something like `make -DmaxVal=42`
Mawg
Hmmm, I *know* that I managed it before, but forget how...I do agree that Eclipse out to be putting the defines into the makefile. I notice makfile lines`-include ../makefile.init'and`-include ../makefile.defs`but these files don't exist(!).The Eclipse CDT guys seem to have dropped the ball as there is no longer a package after upgrading from Jaunty to Karmic. There is a plethora or web pages offering different solutions as to how to install CDT. Maybe the one I chose "almost works". That is to say, works from within CDT, but not externally with `make` ?
Mawg
+1  A: 

You could write a small program to include the headers and write a makefile fragment which you include in the main makefile (requires GNU make).

This is a fairly ugly solution that requires a fair amount of hand hackery. More elegant would be to parse the project file and write the makefile fragment.

dmckee
yes, but the thing is that I know that I did it before without resorting to hackery. Alas, I can no longer remember how.
Mawg
See comment below. Maybe the Jaunty/Kosmic CDT fiasco means I can't repeat whatever I did previously. I may well have to do as you suggest and read in the makefile, massage it and write it out to another makefile.Btw, teh #defines I want to use are not exactly the ones used in Eclipse (e.g, I may swap -Doutput=file for -Doutput=console, etc)
Mawg
+3  A: 

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.

Scott Wales
whoo hoo!! So easy! Thanks, Scott !!
Mawg