开发者

Default flags for gcc compiler in Eclipse

开发者 https://www.devze.com 2022-12-18 15:35 出处:网络
I want all my C programs to be compiled with the options -Wall -pedantic -ansi by default. Is there a way to have Eclipse add these flags 开发者_运维百科to the compiler command by default for all proj

I want all my C programs to be compiled with the options -Wall -pedantic -ansi by default. Is there a way to have Eclipse add these flags 开发者_运维百科to the compiler command by default for all projects?


Assign CFLAGS to include those values, and have Eclipse run a tool that uses that environment variable by default when compiling (such as make).

You may have to specify environment variables before running Eclipse (and then they get inherited when Eclipse runs make) but there might be a way to specify default environment in Eclipse.

(I don't use Eclipse, so I'll have to see about installing and testing this; or maybe this answer can jog someone's memory, if so, feel free to edit.)


As an aside, you might want -std=c99 instead of -ansi. The -ansi option simply means -std=c89 or -std=c++98, depending on whether you're compiling C or C++, and both of those standards are showing their age.


I installed Eclipse inside a VM running Windows to test this, and, even though CFLAGS is in the environment, Eclipse doesn't use it. Eclipse also pretends (by displaying text like "make all" and "make clean") that it's running make in a few situations/projects I tried, when it is not really using make (probably using some internal engine). This answer was on the wrong track for Eclipse.


Assuming you are using Eclipse's internal builder goto Preferences->C/C++ Build->Settings

Choose the warnings section for the compiler, there are tick boxes for -Wall and -pedantic For -ansi set in Miscellaneous

As the OP notes this is just for each project not a global setting


Eclipse on Windows: For a project: Properties -> C/C++ Build -> Setting than "Tool Setting" tab. select "CGG C++ Compiler" than at the right side you will see Command : g++ modify it to Command: g++ CFLAGS for instance if you like to have C++11 support modify as Command: g++ --std=c++11

PS: This modification will valid for only current project and for only current configuration. If you want it for all configurations modify each configuration (Run, Debug) similarly.


EDIT: I see that the OP runs Windows from a prior comment, however the following information may benefit users of Eclipse on the Linux platform, if Eclipse honors the alias.


Are you running Eclipse in Linux? If so, try aliasing the gcc command; run this at a terminal:

alias gcc='gcc -Wall -pedantic -ansi'

This is a common method in Linux to specify default parameters for an application. However, Eclipse might execute the actual gcc application and ignore the alias; I have not tested it.


Yes, Run as -> Run configuration -> 1st Tab is "Main" , choose the second tab(the one next to it) , you have there arguments box, paste -Wall -pedantic -ansi and just apply then run. Every next time you run you'll have these arguments as default

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号