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!

5
  • If you've built an AVR cross-compiler, why pass -mmcu through the -Wp option? Commented Jun 3, 2013 at 8:06
  • I didnt build an AVR cross-compiler, I used the original gcc. Commented Jun 3, 2013 at 9: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. Commented Jun 3, 2013 at 9: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 Commented Jun 3, 2013 at 14:37
  • Hey dwelch, thanks for your comment, if you dont mind have a look at my comment on Beryllium answer. Thanks Commented Jun 4, 2013 at 7:57

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
I've updated my answer. While it could be possible that it compiles, does the ARM executable really run?
Thanks for your update, I switched now to use some toolchain with support for avr.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.