Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add #define in Makefile?

Tags:

c++

makefile

I have a c++ project in which i need to define a variable in some CXX files. I have nearly 800 files out of which i need to define a variable for 200 files. So i was thinking to define it in makefile. So how can we do that.

like image 741
Akhil Pathania Avatar asked Nov 13 '18 19:11

Akhil Pathania


2 Answers

Just add -Dxxx=yy on the command line (xxx the name of the macro and yy the replacement, or just -Dxxx if there is no value).

It's not a Makefile command, it's part of the compiler command line options.

like image 171
Matthieu Brucher Avatar answered Sep 24 '22 04:09

Matthieu Brucher


Let's say you want a replacement for #define MYDEF

In your makefile you have the compiler command line, something like (simplest example):

g++ -o myfile.cpp

To get that #define for every myfile.cpp just use -D like so:

g++ -DMYDEF -o myfile.cpp
like image 38
Ripi2 Avatar answered Sep 22 '22 04:09

Ripi2