cmakefilemacrosavr-gccatmelstudio

How to fix a simple error in Atmel studio


I am programming an Atmega chip using Atmel studio 7. I try to define F_CPU on the first line of the main.c file. This F_CPU definition is used inside the other files. However when I compile the program the F_CPU symbol definition can't be seen by other files and the compiler throws the error shown in the picture. Thanks

The picture showing the error... [enter image description here]


Solution

  • Your #define is only visible in the main.c file. It is not defined in any other source files in your project.

    What you should do:

    define F_CPU in the project properties.

    Right click project > Properties > Toolchain > AVR/GNU C++ Compiler > Symbols
    Configuration: All Configurations
    Under "Defined symbols", add F_CPU=8000000UL
    

    from now on your F_CPU will be visible be all files in your project.

    EDIT

    It is the preferable way of defining this macrodefinition as it is used by Atmel supplied header and source files.