I'm using the SKELETON_JAR
variable on my C++ code in one header. However, I want to allow the user to define the place of the jar in the compile time easily. I think the easiest way to do that is to put this define in makefile is that so?
#define SKELETON_JAR "./Util.jar"
A preprocessor variable is specified in a %DECLARE statement with the FIXED, CHARACTER, or INITIAL attribute. No other attributes can be declared for a preprocessor variable, and attributes must not be repeated. (Other attributes are supplied by the preprocessor, however.)
The #define directive is used to "define" preprocessor "variables", which can then be used in one of three ways, as shown in the following three sections. It is also possible to define preprocessor variables when invoking the compiler, either as command-line arguments or through the IDE.
The C preprocessor is a macro processor that is used automatically by the C compiler to transform your program before actual compilation. It is called a macro processor because it allows you to define macros, which are brief abbreviations for longer constructs.
## is Token Pasting Operator. The double-number-sign or "token-pasting" operator (##), which is sometimes called the "merging" operator, is used in both object-like and function-like macros.
In your code:
#ifndef SKELETON_JAR
#define SKELETON_JAR "./Util.jar" // default path
#endif
and then in the makefile use CPPFLAGS:=-DSKELETON_JAR="./Util.jar"
.
Of course you have to make sure CPPFLAGS
are passed to the compiler as part of the compile rule which is the case if you're using the default implicit rules.
From GNU Make documentation:
Compiling C programs
n.o is made automatically from n.c with a command of the form `$(CC) -c $(CPPFLAGS) $(CFLAGS)'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With