adm34 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

Ability to specify additional compiler flags #421

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A simple option in preferences.txt to change compiler flags instead of having 
them hard-wired in would be very nice.

A way to change it in the GUI would be even better.

Original issue reported on code.google.com by steamra...@yahoo.com on 30 Nov 2010 at 3:12

GoogleCodeExporter commented 9 years ago
I concur with this request. A way to implement it with minimal impact to 
non-techies is:
* Check for the existence of (boardname).build.CFLAGS (or something in 
preferences.txt, depending on what level of granularity is desired)
* If the tag exists, use the contents with the avr-gcc command
* else use what is there already in the code

Original comment by ste...@c88.org on 25 Feb 2011 at 8:47

GoogleCodeExporter commented 9 years ago
From Paul Stoffregen:

I'd suggest these 3:

board.build.cflags=
board.build.cppflags=
board.build.asmflags=

If you really wanted to go crazy, maybe a 4th:

board.build.ldflags=

All of these are very simple to implement in Compiler.java.  If they're not 
null, just add whatever they define to the List object before calling 
execAsynchronously.

All of them (sketch, core, and libraries)?

Yes, the same flags applied to all files of the same type ( .c, .cpp, and .s ), 
regardless of sketch, library or core.

Compiler.java uses the same "compileFiles" for sketch, core and libraries.  
It'd be pretty easy to add these in getCommandCompilerS, getCommandCompilerC, 
and getCommandCompilerCPP.

For example, inside getCommandCompilerC:

   String flags = boardPreferences.get("build.cflags");
   if (flags != null) baseCommandCompiler.add(flags);

Or near the end of step #4:

   String ldflags = boardPreferences.get("build.ldflags");
   if (ldflags != null) baseCommandLinker.add(ldflags);

Original comment by dmel...@gmail.com on 5 Mar 2011 at 7:38

GoogleCodeExporter commented 9 years ago
I'd actually like to see the user-specified flags *replace* the default flags, 
instead of just *add* to them. There may be cases where I don't want one of the 
flags hard-coded in the IDE...

Original comment by ste...@c88.org on 5 Mar 2011 at 8:59

GoogleCodeExporter commented 9 years ago
Yes, but replacing the flags makes the implementation more complicated.  Are 
there particular flags you have in mind?

Original comment by dmel...@gmail.com on 6 Mar 2011 at 4:26

GoogleCodeExporter commented 9 years ago
I can think of a few I may want to override:

      "-w", // surpress all warnings

I may want to see the warnings, to make my code better.

      "-Os", // optimize for size

I may want another optimization instead.

As I look at it more, these are the only options which make sense to override. 
The others are probably OK.

Original comment by ste...@c88.org on 6 Mar 2011 at 6:47

GoogleCodeExporter commented 9 years ago
What happens if you specify multiple, conflicting options on the same command 
line?  For example, "-Os" followed by "-O2".  That is, I'm wondering if we can 
allow people to override the -Os option just by including another optimization 
level in the general cflags preference.  Similarly for warnings, although I'd 
also like to enable some warnings if verbose compilation is enabled (issue 
#498).

Original comment by dmel...@gmail.com on 7 Mar 2011 at 4:06

GoogleCodeExporter commented 9 years ago
I don't know the answer to that, as I have not tried it. I wouldn't think that 
the later option overrides the earlier one, but I could be totally wrong...

Original comment by ste...@c88.org on 7 Mar 2011 at 6:30

GoogleCodeExporter commented 9 years ago
Issue 545 has been merged into this issue.

Original comment by dmel...@gmail.com on 24 May 2011 at 4:22

GoogleCodeExporter commented 9 years ago
I have worked a little on this issue, implementing the option in the GUI for 
which optimization level the user wants.

This is saved in preferences.txt and could easily be changed to suit your needs.

My code can be seen on my fork on Git hubhttps://github.com/nbjensen/Arduino

Other flags that might be relevant or all -f... flags, which are passed on by 
avr-gcc. This could be -fdump-tree-all, which would lead to each tree 
optimization pass dump a file describing which optimization applied.

Original comment by nbjen...@gmail.com on 29 Aug 2011 at 9:06

GoogleCodeExporter commented 9 years ago
I'm using the following lines in the preferences.txt (I modify the user local 
file when the IDE is closed):
avr-gcc.options=-O3
avr-g++.options=-O3
but when I look at the compile and build process (I use build.verbose=true to 
check)
I see it uses the default options (-g -Os ....)
where am I wrong

Original comment by paoloboa...@tiscali.it on 3 Sep 2011 at 4:02

GoogleCodeExporter commented 9 years ago
Issue 781 has been merged into this issue.

Original comment by dmel...@gmail.com on 9 Jan 2012 at 12:48

GoogleCodeExporter commented 9 years ago
Hi David, re comment #6: gcc is a typical Unix program here, where in a set of 
1-of-N choices the last one seen on the command line is the effective one. So 
-Os -O3 will make -O3 effective. For binary switches gcc provides an on as well 
as an off, e.g. -Werror -Wno-error. Only the last one is relevant. The same 
holds for all the optimisation switches, which all start with -f. For each 
-fXXX there is a -fno-XXX. Only the last one counts. Although the help output 
of avr-gcc --help doesn't mention this, the gcc manual is good and I'm certain 
it's mentioned in there.

I am unable to confirm whether there is an option undoing the effect for every 
option that does something, but I am sure there are for most.

Original comment by gooc...@top.geek.nz on 14 Jan 2012 at 10:22

GoogleCodeExporter commented 9 years ago
The easy solution is to read the default compiler options from the preferences 
file. Hardcoding important settings like these is always bad practice. That way 
if someone find they really have to change it they can keep going with a text 
editor.

Splendid would be to have a text entry box in the GUI, separately for C/C++/asm 
(Paul in #2 knows what he's talking about), for options that are added to the 
default options. The ldflags one is not crazy, it allows more flexibility at 
the linker stage, e.g. to use other libraries (those libXXX.a, not what Arduino 
calls library).

The real problem seems to be that the need for changing compiler options is not 
understood. The Arduino IDE must get the prize for the only tool not being able 
to do so. It's not professional - unless of course the design goal is that the 
IDE is only used by beginners or for basic jobs.

IMO the IDE's job is to provide a default, but not to be in the way of users 
who need to change options. I am ditching the IDE now because it doesn't get 
the job done. The job requires different compiler options.

Don't try to hit all the possible compiler options people might want with a few 
radio buttons, unless you like lost causes. Look at some other tools at the 
profesional level, e.g. eclipse. It has selection boxes for some common 
categories, like code optimisation level, macros, basic warnings - and it has a 
catch-all box for the rest. I'm certain there would be mutiny if that box 
wasn't there.

Some of my requirements (remember this is not and never will be complete):

* Better warnings. This finds problems early. I read that Arduino is often used 
as a teaching tool. For a teaching example the state of the core software is 
quite shocking. Good examples provide no compiler warnings, or at least their 
header files don't bombard the user with warnings if the user decides to set 
the warning level to maximum for their own programs. I strongly suggest Arduino 
developers run their wiring code through maximum warning levels - it shows just 
how bad it is. It might even find a bug.

* Different optimisations. I claim the final decision of where and how I want 
my source to be optimised for myself, because I know my project best. I wanted 
to test LTO in newer compilers, but it needs more options. The IDE, while 
allowing to use any compiler (by setting up $PATH appropriately), is useless 
for this.

* Macro definitions with -D. I want to be able to make generic code that can be 
re-used in multiple projects, but there isn't code space for some code branches 
that are never used, and gcc isn't good enough to eliminate them automatically. 
It needs pre-processor help. Obviously this makes it unsuitable for libraries, 
that's a compromise I have to accept.

You could of course argue that those who need other compiler options use 
something other than the IDE anyway. On the other hand implementing this 
feature isn't exactly difficult. I would have found it very useful over a year 
ago.

Original comment by gooc...@top.geek.nz on 14 Jan 2012 at 11:34

GoogleCodeExporter commented 9 years ago
Here is a possible patch to implement this:
https://github.com/srejbi/Arduino/commit/f53db6aab6b461975a3682c19b6d5d6f329defa
a

Original comment by Gregor.G...@gmail.com on 8 May 2012 at 10:35

GoogleCodeExporter commented 9 years ago
Any comment on this from the maintainers? Maybe putting the configuration 
options on the Preferences dialog would be too intimidating and error-prone for 
beginners, but there is no excuse for not using Preferences.txt.

Original comment by o...@wanadoo.es on 14 Nov 2012 at 9:29

GoogleCodeExporter commented 9 years ago
Perhaps if not at build, then at startup, to read the command line parameters 
from the preferences.txt file (excluding the things that change for each file 
like -o) and if they don't exist, write the defaults to the file.  This way, 
they can be fully customised while allowing for defaults to be reset by simply 
erasing them.

How far is it till anything on this thread will be implemented?

Original comment by adrian.h...@gmail.com on 26 Apr 2013 at 5:38

GoogleCodeExporter commented 9 years ago
+1 for making this happen, and +1 for replacing the existing flags. (Is there a 
"turn it off" syntax for the --relax linker flag?

Original comment by greg.nas...@gmail.com on 27 May 2013 at 6:54

GoogleCodeExporter commented 9 years ago
+1 - it would be very helpy to include e.g. the Wire-thinks direct to libary 
which use it

Original comment by mifritsc...@gmail.com on 16 Nov 2013 at 6:09

GoogleCodeExporter commented 9 years ago
It seems like the Arduino IDE will never be really improved. Look at all the 
extremely basic features it is missing:

* Compiler options.
* Antialiased text!
* Tabs !!
* In fact any indentation other than two spaces!!!

At this point I don't know why they don't abandon it and reimplement Arduino as 
a QtCreator plugin, or at least provide a simple command line interface to the 
compiler so it can *easily* be used from other IDEs.

Original comment by tdh...@gmail.com on 18 Nov 2013 at 12:46

GoogleCodeExporter commented 9 years ago
I've missed this issue, but this was implemented in IDE 1.5.x through the 
platform.txt file that you can find in the hardware folder, you can find some 
more documentation here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5---3rd-party-Hardware-spe
cification

There is also antialiasing, and a command line interface:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-from-command-line

C

Original comment by c.mag...@arduino.cc on 18 Nov 2013 at 12:59

GoogleCodeExporter commented 9 years ago
Correct. The reasons are obvious: The Arduino IDE is made for and meant
for beginners who need something very basic to get going, and who should
not need to know what a compiler flag is. I suggested this feature years
ago and it's still not in any released version. For any semi-serious use
compiler flags and defines (-D) are non-negotiable, so I looked for
better ways.

If you want total freedom for your program while remaining 100%
compatible with the Arduino IDE use my makefile:

http://volker.top.geek.nz/arduino/

It is by far the most comprehensive makefile that seemlessly integrates
with the Arduino environment as far as I know. You can use any IDE you
want, I have used eclipse 3.7 (bloated), codeblocks (missing essential
features like code completion or navigation - it's there, but so basic
as to be basically useless), and of course there always is $EDITOR.

You can then concentrate on your program rather then having some IDE in
the way that is not (mean to be) up to a more professional standard.

And you'll find the ability to build and upload from the command line to
be a huge bonus sometimes.

Original comment by gooc...@top.geek.nz on 18 Nov 2013 at 6:59

GoogleCodeExporter commented 9 years ago
Apologies, it wasn't me who opened this issue, someone else bet me to
it.

Original comment by gooc...@top.geek.nz on 18 Nov 2013 at 8:47

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
As a work-around, you can use the small proxy program I wrote. It should be 
compilable with your favorite compiler.

1. Compile the program.
2. Rename the original avr-g++.exe to avr-g++.orig.exe (or any other name).
3. Create avr-g++.ini file where the first line is FULL path to the original 
program (e.g. D:\Arduino\hardware\tools\avr\bin\avr-g++.orig.exe) and add 
additional parameters, one per line, as desired. 

You're done!

Example avr-g++.ini:
D:\Arduino\hardware\tools\avr\bin\avr-g++.orig.exe
-std=c++0x

Hope, that helps!

Original comment by fax.k.r...@gmail.com on 1 Feb 2014 at 11:34

Attachments: