[Ilugc] Changing default CFLAGS flags for gcc

  • From: girishvenkatachalam@xxxxxxxxx (Girish Venkatachalam)
  • Date: Thu Sep 3 06:17:06 2009

On Thu, Sep 3, 2009 at 12:06 AM, narendra babu<cnarendra_babu@xxxxxxxxx> wrote:


hi ,

I have lot of makefiles ?, by default gcc geneartes 64 bit executable on 64 
machine ?but i need to change to 32 bit , dont want to change the makefiles .

Ok.


Instead is there anyway i can change default flags at command line for gcc

I think there is.

Can i set environment variable
export CFLAGS=-m32 CXX=-m32 ?so that by gcc takes CFLAGS or CXX to generate 
32bit code instead of 64 bit code by default .

I dunno which one gets preference. You have to check and read
the documentation on GNU Make.

If the Makefile CFLAGS takes preference then you will have no
choice but to modify it in all Makefiles.

I will give you a command by which you can do it in one stroke.

Typically CFLAGS will already be used in Makefiles. So you want
to add to it. I am assuming here that you are not having any flag
that will reset this -m32 or whatever flag you want to set.

Then this command will change all files at one go.

$ vim -p foo/Makefile ba/Makefile foo/bar/Makefile

Inside vim enter this command:

:tabdo :%s/CFLAGS=/CFLAGS+=-m32/g

If this command goes through then you can save all files and
exit at one stroke with

:tabdo wq

Please remember that you may not get the same results I expect.

You should follow along these lines.

If you don't like tabbed vim, you could go for :bufdo if you use vi
or vim without -p flag. That should give the same results too.


So in simple i want to chnage the gcc default flag settings

Like $CFLAGS=-m32 gcc hello.c should generate me 32 bit code on a 64 bit 
machine instead of 64 bit .

I dunno this. I have never used a 64 bit machine.

Note : As by default all my makefiles can take the default CFLAGS which is 
set as environment variable .


I guess so.

-Girish

-- 
Gayatri Hitech
web: http://gayatri-hitech.com

SpamCheetah Spam filter:
http://spam-cheetah.com

Other related posts: