Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing C/C++ #defines to makefile

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

like image 562
Mawg says reinstate Monica Avatar asked Jan 11 '10 02:01

Mawg says reinstate Monica


People also ask

What is passing in C?

Pass by Value, means that a copy of the data is made and stored by way of the name of the parameter. Any changes to the parameter have NO affect on data in the calling function.

Can you pass by value in C?

C always uses 'pass by value' to pass arguments to functions (another term is 'call by value', which means the same thing), which means the code within a function cannot alter the arguments used to call the function, even if the values are changed inside the function.

Why is C pass by value?

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C programming uses call by value to pass arguments.

What is passing parameters in C?

Parameter passing involves passing input parameters into a module (a function in C and a function and procedure in Pascal) and receiving output parameters back from the module. For example a quadratic equation module requires three parameters to be passed to it, these would be a, b and c.


2 Answers

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.

like image 133
Scott Wales Avatar answered Sep 18 '22 16:09

Scott Wales


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.

like image 39
dmckee --- ex-moderator kitten Avatar answered Sep 21 '22 16:09

dmckee --- ex-moderator kitten