gcc and command line symbols

A

AB

Hello All,

I've got code like this...

#ifdef SYMBOL
..
..
..

/* Do stuff */
..
..
..
#endif

I want to define SYMBOL on the command line. Which switch should I use
when compiling with gcc?
 
V

Vladimir Oka

AB said:
Hello All,

I've got code like this...

#ifdef SYMBOL
.
.
.

/* Do stuff */
.
.
.
#endif

I want to define SYMBOL on the command line. Which switch should I use
when compiling with gcc?

Off-topic, but: -D tends to worrk for most compilers I ever used.
 
C

Clever Monkey

AB said:
Hello All,

I've got code like this...

#ifdef SYMBOL
.
.
.

/* Do stuff */
.
.
.
#endif

I want to define SYMBOL on the command line. Which switch should I use
when compiling with gcc?
man gcc
 
K

Keith Thompson

AB said:
Hello All,

I've got code like this...

#ifdef SYMBOL
.
.
.

/* Do stuff */
.
.
.
#endif

I want to define SYMBOL on the command line. Which switch should I use
when compiling with gcc?

"info gcc" should give you the gcc documentation on most systems.
 
D

David Wade

Keith Thompson said:
"info gcc" should give you the gcc documentation on most systems.

On some systems, without "man" or "info" you may need to use "gcc -v --help"
 
S

SM Ryan

# > Hello All,
# >
# > I've got code like this...
# >
# > #ifdef SYMBOL

On the command line include -DSYMBOL to simulate
#define SYMBOL
and -DSYMBOL=VALUE for
#define SYMBOL VALUE

For example,
(cd /tmp
cat >t.c <<':eof'
#include <stdio.h>
int main(int n,char **p) {
#ifdef P
printf("P\n");
#endif
#ifdef Q
printf("Q\n");
#endif
printf("least random number %d\n",R);
return 0;
}
:eof
cc -DP -DR=17 t.c
a.out)

# "info gcc" should give you the gcc documentation on most systems.

Once again wasting more bandwidth not answerring the question then
a simple answer would've provided.
 
K

Keith Thompson

SM Ryan said:
Once again wasting more bandwidth not answerring the question then
a simple answer would've provided.

Somebody else had mentioned "-D" before I posted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top