954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Preprocessor definitions on the command line

Hi, I need to have my compiler take preprocessor definitions from the
command line. How does it differ from normal command line parameter passing (main(int arc, char *argv[])) ?
Thanks.

ejptccs123
Newbie Poster
2 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

It depends on the compiler; you'll usually see things like -D or \D. Look it up in your documentation.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

Thanks for the tip. I'm using Dev-C++. And I got the preprocessor flag to work.
Thanks.

ejptccs123
Newbie Poster
2 posts since Oct 2004
Reputation Points: 10
Solved Threads: 0
 

i need it fastHi, I need to have my compiler take preprocessor definitions from the
command line. How does it differ from normal command line parameter passing (main(int arc, char *argv[])) ?
Thanks.

paramaguru
Newbie Poster
1 post since Nov 2006
Reputation Points: 8
Solved Threads: 0
 

1. g++ -DHAVE_CONFIG -Wall -std=c++98 -o myprogram
2. ,/myprogram hello world

in 1., the command line args are used by the c preprocessor, some are forwarded to the compiler and linker

in 2., the command line args are passed to myprogram and are available as parameters passed to main

vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

preprocessor directives/macros are processed at the time of compilation. Arguments relevant to preprocessor (e.g. -DXXX=value) are passed to compiler and used by compiler. Any argument passed on command line is called command line arguments. :). So these are the CLI args to compiler.
After compilation (and linking) the executable of your program is ready.. when you call/execute this executable with CLI args, these would go to main() and will be be available to your program.

thekashyap
Practically a Posting Shark
811 posts since Feb 2007
Reputation Points: 254
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You