C ++ Preprocessor Variable

I use the SKELETON_JAR variable for my C ++ code in one header. However, I want the user to be able to easily locate the jar at compile time. I think the easiest way to do this is to set this definition in a makefile like that?

 #define SKELETON_JAR "./Util.jar" 
+6
c ++ c-preprocessor makefile
source share
3 answers

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 that CPPFLAGS passed to the compiler as part of the compilation rule, if you use implicit rules by default.

From GNU Make documentation :

Compiling C Programs

no is generated automatically from nc using the command `` $ (CC) -c $ (CPPFLAGS) $ (CFLAGS) '

+8
source share

Depending on your compiler, the usual way to do this is to use the -D compiler flag in the makefile. For example:

MYFLAGS = -DSKELETON_JAR = "foo"

and then:

gcc $ (MYFLAGS) $ (OTHER_STUFF)

+6
source share

Use compilation flags for them and define a flag in the Makefile.

0
source share

All Articles