LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-19-2011, 11:05 AM   #1
thebombzen
Member
 
Registered: Dec 2010
Location: Noneya Business
Distribution: Linux Mint
Posts: 56

Rep: Reputation: 5
Question Set universal CFLAGS that gcc automatically sees


I have a project I'm constantly building that doesn't use a makefile, but I want to set CFLAGS anyway. Just setting the CFLAGS environment variable won't change the options gcc actually uses. Is there a way to set some kind of variable that gcc will pick up and use? (Changing some file on my hard drive with default cflags also works too.)

EDIT: Here's an example:

Code:
[Leo@chessman ~]$ cat test.c
#include <stdio.h>

int main(){

#ifdef HELLO
	printf("Hello\n");
#else
	printf("Not Hello\n");
#endif
	return 0;
}

[Leo@chessman ~]$ export CFLAGS=-DHELLO
[Leo@chessman ~]$ gcc -o test test.c
[Leo@chessman ~]$ ./test
Not Hello
[Leo@chessman ~]$ gcc -DHELLO -o test test.c
[Leo@chessman ~]$ ./test
Hello
[Leo@chessman ~]$
For example, Is there some substitute for "export CFLAGS=-DHELLO" that will make gcc define HELLO?

Last edited by thebombzen; 08-19-2011 at 01:25 PM.
 
Old 08-20-2011, 05:37 AM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
You could use your shell for this, just alias gcc to "CFLAGS="foo bar moo cow" gcc". If you want it for your user then use your ~/.bashrc or ~/.bash_profile, if you want it system-wide then you probably should use /etc/profile. The details however depend on the shell you use. I assumed it's bash, which might not be true.
 
1 members found this post helpful.
Old 08-20-2011, 09:47 AM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
You can use make without a makefile, there are some builtin rules:

Code:
$ ls -a
.  ..  test.c
$ export CFLAGS=-DHELLO
$ make test
cc -DHELLO    test.c   -o test
$ ./test
Hello
$
 
Old 08-22-2011, 10:20 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
And why not just add Makefile?
 
  


Reply



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
Default CFLAGS in gcc when none are specified? amiga32 Programming 7 10-22-2010 05:41 AM
[SOLVED] Is this how you set CFLAGS and other Make options? agi93 Slackware 6 01-02-2010 02:25 PM
export CFLAGS GCC help TieN Programming 2 06-17-2005 03:24 AM
Why can't a universal progarm write drivers based on the actual hardware it sees? SoccerballTux Linux - Software 3 06-09-2005 09:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:17 AM.

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