2011-06-26 10 views
11

Al crear un proyecto en AVR Studio 5, se crea un archivo .c con los siguientes contenidos:AVR Studio 5: Código de compilar C++

#include <avr/io.h> 

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

La construcción de este programa C funciona bien:

------ 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 ========== 

Pero cuando cambio la extensión de archivo a .cpp, la compilación emite la advertencia tipo de dispositivo no definido (que se convertirá en un error si se intenta utilizar cualquier registro específico de 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 ========== 

La comparación de ambas salidas muestra que para el código C agrega la opción -mmcu=atmega328p a avr-gcc.exe, pero para el código C++ no lo hace al ejecutar avr-g++.exe. Problema similar que tengo al usar WinAVR. ¿Cómo resolver esto?

+1

He encontrado una solución alternativa: cambie el nombre de todos los archivos .cpp a .c y defina las siguientes opciones de compilación: '-x C++ -std = gnu ++ 98'. – Mot

+0

¿Podría publicar su comentario como respuesta y aceptarlo? De esta forma, la pregunta dejará de aparecer como sin respuesta. –

Respuesta

7

He encontrado una solución alternativa: cambie el nombre de todos los archivos .cpp a .c y defina las siguientes opciones de compilación: -x c++ -std=gnu++98.

0

¿Ha intentado abrir el cuadro de diálogo del proyecto y verificar que el tipo de dispositivo esté configurado?

+0

Claro, de lo contrario no habría funcionado con la variante C. – Mot

5

me di cuenta que es una adición tardía, pero en caso de que alguien se tropieza demás sobre esto:

¿Ha notado que hay una extensión C++ disponible para AVR Studio 5 en Herramientas -> Administrador de extensiones? Esto le permite crear proyectos C++ con extensiones .cpp y todo. Source

Cuestiones relacionadas