Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-31-2007, 08:33 AM   #1
LQ Newbie
Registered: Mar 2007
Posts: 13

Rep: Reputation: 0
Add preprocessor from console

I have defined some preprocessor into my project. Something like

//perform encryption activity
//do normal operation
How to add this preprocessor into my project from the terminal, so that I can perform encryption activity?

Old 08-31-2007, 08:45 AM   #2
Senior Member
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 63
I don't quite get what you mean. If you really have the //comments, then you have this:
... misc code...
//perform encryption activity
... misc code...
//do normal operation
... misc code...
Then this should do what you want:
find /path/to/project -type f
 -exec grep -Fxq '//perform encryption activity' '{}' \;
 -exec grep -Fxq '//do normal operation' '{}' \;
 -exec sed -i -e '/^\/\/perform encryption activity$/ i#ifdef _ENCRYPTION_' -e '/^\/\/do normal operation$/ i#endif' '{}' \;
This is a single command (one line), broken into several lines here for better readability.

This shell command finds files that contain both comments, and inserts the preprocessor commands above the comments.
I did not test, so try with a test folder first.


Last edited by theYinYeti; 08-31-2007 at 08:47 AM.
Old 08-31-2007, 08:55 AM   #3
LQ Newbie
Registered: Mar 2007
Posts: 13

Original Poster
Rep: Reputation: 0
what I meant was how to add the preprocessor (_ECNRYPTION_) to the makefile from the terminal.

for eg.
:>qmake //creates a makefile
:>make //compiles

In the above example how to add the preprocessor (_ECNRYPTION_) to the makefile generated, from the terminal.

Old 08-31-2007, 10:04 AM   #4
Wim Sturkenboom
Senior Member
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I think what you looking for is the -D option for gcc
From man gcc:
-D name
Predefine name as a macro, with definition 1.

-D name=definition
The contents of definition are tokenized and processed as if they
appeared during translation phase three in a #define directive. In
particular, the definition will be truncated by embedded newline
I've never used it, so you must figure it out yourself or wait till someone else comes along. And as far as I know it's called a preprocessor directive.

PS There is a dedicated programming section. Usefull for future programming related questions.

Last edited by Wim Sturkenboom; 08-31-2007 at 10:07 AM. Reason: Added PS


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
The C Preprocessor slzckboy Programming 9 04-15-2007 02:46 PM
C pre-preprocessor or preprocessor replacement Tischbein Programming 3 02-11-2007 12:38 PM
How do you add new printer from the text console? (Minimal installation) Akhran Debian 3 06-28-2006 09:20 AM
add a program to run in vty/console at boot? carl0ski Mandriva 3 11-23-2004 07:07 AM
how to add a directory from the console FuGeE Linux - General 1 08-06-2003 01:52 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:39 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration