1

I want to generate the assembly file of my code oriented to the AVR architecture, I am using gcc version 4.7.2 with the following arguments:

g++ -O3 -Wall -S -Wp,-mmcu=atmega8 -o "src\Compression.o" "..\src\Compression.cpp"

but I am getting the following error:

cc1plus.exe: error: unrecognized command line option '-mmcu=atmega8'

But I got the command options from the gcc website: http://gcc.gnu.org/onlinedocs/gcc-4.7.3/gcc/AVR-Options.html#AVR-Options

There should be something that I am missing, could you help me with this please!

Maher Assi
  • 75
  • 3
  • 10
  • If you've built an AVR cross-compiler, why pass `-mmcu` through the `-Wp` option? – Brett Hale Jun 03 '13 at 08:06
  • I didnt build an AVR cross-compiler, I used the original gcc. – Maher Assi Jun 03 '13 at 09:08
  • In the gcc website they stated that I can use the -mmcu as a command line option, but it requires the use of -Wp so as to pass this option to the preprocessor. – Maher Assi Jun 03 '13 at 09:09
  • gcc is a single target compiler, when gcc itself is built you have to tell it which target, what processor family, it will compile for. if you want a host (x86 lets assume), an arm cross compiler and an avr cross compiler for example you need three separate installations of gcc, one for each target. gcc isnt llvm/clang you cant have one compiler generate code for multiple targets. If it doesnt recognize the command line option then the gcc you are using is likely for a different target – old_timer Jun 03 '13 at 14:37
  • Hey dwelch, thanks for your comment, if you dont mind have a look at my comment on Beryllium answer. Thanks – Maher Assi Jun 04 '13 at 07:57

1 Answers1

5

If gcc does not accept -mmcu, you are probably not using a gcc with support for the AVR architecture.

It's normally used like this:

avr-gcc -mmcu=atmega328p

because it's not only the preprocessor, it's actually other tools as well which require this setting (linker, assembler).

Normally the architecture gcc is compiled for is indicated by a prefix, in this case it's avr- by convention.

So the solution is to get a toolchain with AVR support. You can download it from Atmel's web site, even for Linux.

Update

If you like to check the configuration of your gcc, you can use -dumpmachine to check for the target processor

$ gcc -dumpmachine
i486-linux-gnu

$ arm-none-eabi-gcc -dumpmachine
arm-none-eabi

$ avr-gcc -dumpmachine
avr

If you look at the target specific options using --target-help

$ gcc --target-help | grep march
-march= Generate code for given CPU

you can see that the Linux gcc does accept -march as well. It probably fails later.

gcc is a very complex piece of software, because it just supports so many different architectures. From that perspective it works amazingly well.

Another interesting option is -v

$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8'
[...]

to see how that gcc has been built.

And there could be another trap down the road (multi-libs), as you can see here

Community
  • 1
  • 1
Beryllium
  • 12,808
  • 10
  • 56
  • 86
  • Thanks for answer. What surprised me actually was that gcc would accept the line arguments for arm architecture (-march=..), but it didnt accept the line arguments for the avr architecture, knowing that the gcc website says it proviedes both of them. Anyway thanks for your answer, although I still dont understand why compiling for arm works but for avr it doesnt. I guess I can use avr-gcc. – Maher Assi Jun 04 '13 at 07:57
  • I've updated my answer. While it could be possible that it compiles, does the ARM executable really run? – Beryllium Jun 04 '13 at 08:37
  • Thanks for your update, I switched now to use some toolchain with support for avr. – Maher Assi Jun 15 '13 at 07:31