2011-06-26 100 views
11

當建立在AVR Studio的5項目,它將創建一個具有以下內容的.c文件:了AVR Studio 5:編譯C++代碼

#include <avr/io.h> 

int main(void) 
{ 
    while(1) 
    { 
     //TODO:: Please write your application code 
    } 
} 

建設這個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 ========== 

但是,當我將文件擴展名更改爲.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 ========== 

比較兩個輸出表明,對於C代碼,它將選項-mmcu=atmega328p添加到avr-gcc.exe,但是對於C++代碼,它不會在執行avr-g++.exe時添加。我在使用WinAVR時遇到類似的問題。如何解決這個問題?

+1

我找到了一種解決方法:將所有.cpp文件重命名爲.c並定義以下編譯器選項:'-x C++ -std = gnu ++ 98'。 – Mot

+0

您能否將您的評論發佈爲答案並接受它?這樣,問題就會停止顯示爲未答覆。 –

回答

7

我找到了一種解決方法:將所有.cpp文件重命名爲.c並定義以下編譯器選項:-x c++ -std=gnu++98

0

您是否嘗試打開項目對話框並檢查設置的設備類型?

+0

當然,否則它不會與C變體一起使用。 – Mot

5

我意識到這是一個晚此外,但在這種情況下任何人絆倒:

你有沒有注意到,還有下一個工具C++擴展可用於AVR Studio的5 - >擴展管理器?這使您可以創建帶有.cpp擴展名和所有內容的C++項目。 Source