When creating a project in AVR Studio 5, it creates a .c file with following content:
在AVR Studio 5中创建项目时,会创建一个.c文件,内容如下:
#include <avr/io.h>
int main(void)
{
while(1)
{
//TODO:: Please write your application code
}
}
Building this C program works just fine:
构建这个C程序非常有效:
------ Rebuild All started: Project: AVRGCC2, Configuration: Debug AVR ------
Build started.
Project "AVRGCC2.avrgccproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "C:\Dokumente und Einstellungen\tom\Eigene Dateien\AVRStudio\test\AVRGCC2\AVRGCC2\AVRGCC2.avrgccproj" (target "ReBuild" depends on it):
Task "RunAvrGCC"
C:\Programme\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe clean all
rm -rf AVRGCC2.o AVRGCC2.d libAVRGCC2.a AVRGCC2.hex AVRGCC2.eep AVRGCC2.lss AVRGCC2.map
AVRGCC2.c
Invoking: AVR/GNU C Compiler
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -O0 -fpack-struct -fshort-enums -g2 -Wall -c -std=gnu99 -mmcu=atmega328p -MD -MP -MF"AVRGCC2.d" -MT"AVRGCC2.d" -o"AVRGCC2.o" ".././AVRGCC2.c"
Finished building: .././AVRGCC2.c
Building target: AVRGCC2.elf
Invoking: AVR/GNU C/C++ Linker
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -mmcu=atmega328p -Wl,-Map=AVRGCC2.map -o AVRGCC2.elf AVRGCC2.o
Finished building target: AVRGCC2.elf
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "AVRGCC2.elf" "AVRGCC2.hex"
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "AVRGCC2.elf" > "AVRGCC2.lss"
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "AVRGCC2.elf" "AVRGCC2.eep" || exit 0
AVR Memory Usage
----------------
Device: atmega328p
Program: 142 bytes (0.4% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Done executing task "RunAvrGCC".
Done building target "CoreRebuild" in project "AVRGCC2.avrgccproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "C:\Dokumente und Einstellungen\tom\Eigene Dateien\AVRStudio\test\AVRGCC2\AVRGCC2\AVRGCC2.avrgccproj" (entry point):
Done building target "ReBuild" in project "AVRGCC2.avrgccproj".
Done building project "AVRGCC2.avrgccproj".
Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
But when I change the file extension to .cpp, the build issues the warning device type not defined (which will turn into an error if trying to use any AVR specific register):
但当我将文件扩展名更改为.cpp时,构建会发出未定义的警告设备类型(如果尝试使用任何AVR特定寄存器,则会变成错误):
------ Rebuild All started: Project: AVRGCC2, Configuration: Debug AVR ------
Build started.
Project "AVRGCC2.avrgccproj" (ReBuild target(s)):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreRebuild" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "C:\Dokumente und Einstellungen\tom\Eigene Dateien\AVRStudio\test\AVRGCC2\AVRGCC2\AVRGCC2.avrgccproj" (target "ReBuild" depends on it):
Task "RunAvrGCC"
C:\Programme\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe clean all
In file included from .././AVRGCC2.cpp:1:0:
c:\programme\atmel\avr studio 5.0\avr toolchain\bin\../lib/gcc/avr/4.5.1/../../../../avr/include/avr/io.h(446,6): #warning "device type not defined"
rm -rf AVRGCC2.o AVRGCC2.d libAVRGCC2.a AVRGCC2.hex AVRGCC2.eep AVRGCC2.lss AVRGCC2.map
AVRGCC2.cpp
Invoking: AVR/GNU CPP Compiler
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-g++.exe" -MD -MP -MF"AVRGCC2.d" -MT"AVRGCC2.d" -o"AVRGCC2.o" ".././AVRGCC2.cpp"
Finished building: .././AVRGCC2.cpp
Building target: AVRGCC2.elf
Invoking: AVR/GNU C/C++ Linker
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -mmcu=atmega328p -Wl,-Map=AVRGCC2.map -o AVRGCC2.elf AVRGCC2.o
Finished building target: AVRGCC2.elf
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature "AVRGCC2.elf" "AVRGCC2.hex"
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "AVRGCC2.elf" > "AVRGCC2.lss"
"C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "AVRGCC2.elf" "AVRGCC2.eep" || exit 0
AVR Memory Usage
----------------
Device: atmega328p
Program: 142 bytes (0.4% Full)
(.text + .data + .bootloader)
Data: 0 bytes (0.0% Full)
(.data + .bss + .noinit)
Done executing task "RunAvrGCC".
Done building target "CoreRebuild" in project "AVRGCC2.avrgccproj".
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
Target "ReBuild" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "C:\Dokumente und Einstellungen\tom\Eigene Dateien\AVRStudio\test\AVRGCC2\AVRGCC2\AVRGCC2.avrgccproj" (entry point):
Done building target "ReBuild" in project "AVRGCC2.avrgccproj".
Done building project "AVRGCC2.avrgccproj".
Build succeeded.
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
Comparing the both outputs shows that for the C-code it adds the option -mmcu=atmega328p
to avr-gcc.exe
but for the C++-code it doesn't when executing avr-g++.exe
. Similar problem I have when using WinAVR. How to solve this?
比较两个输出,可以发现C-code中添加了选项-mmcu=atmega328p到avr-gcc。exe但是对于c++代码,在执行avr-g+ .exe时就不需要了。我在使用WinAVR时遇到过类似的问题。如何解决呢?
3 个解决方案
#1
7
I've found one workaround: rename all .cpp
files to .c
and define following compiler options: -x c++ -std=gnu++98
.
我找到了一个变通方法:将所有.cpp文件重命名为.c,并定义以下编译器选项:-x c++ + -std=gnu+ 98。
#2
5
I realize this is a late addition, but in case anyone else stumbles upon this:
我知道这是一个迟来的补充,但如果有人偶然发现:
Have you noticed that there's a C++ extension available for AVR Studio 5 under Tools -> Extension Manager? This lets you create C++ projects with .cpp extensions and everything. Source
您是否注意到在工具->扩展管理器下,AVR Studio 5有一个c++扩展?这允许您创建带有.cpp扩展和其他所有功能的c++项目。源
#3
0
Have you tried opening the project dialog box and checking that the devicetype is set?
您是否尝试过打开项目对话框并检查devicetype是否设置?
#1
7
I've found one workaround: rename all .cpp
files to .c
and define following compiler options: -x c++ -std=gnu++98
.
我找到了一个变通方法:将所有.cpp文件重命名为.c,并定义以下编译器选项:-x c++ + -std=gnu+ 98。
#2
5
I realize this is a late addition, but in case anyone else stumbles upon this:
我知道这是一个迟来的补充,但如果有人偶然发现:
Have you noticed that there's a C++ extension available for AVR Studio 5 under Tools -> Extension Manager? This lets you create C++ projects with .cpp extensions and everything. Source
您是否注意到在工具->扩展管理器下,AVR Studio 5有一个c++扩展?这允许您创建带有.cpp扩展和其他所有功能的c++项目。源
#3
0
Have you tried opening the project dialog box and checking that the devicetype is set?
您是否尝试过打开项目对话框并检查devicetype是否设置?