Code::Blocks template Arduino Duemilanove atm328p

Hello,

This template may be useful to someone, who started to play with Arduino IDE but wants to change to Code::Blocks.

Set up for Windows:
Create an ArduinoProject dir in the
C:\Documents and Settings<your login name>\Application Data\codeblocks\UserTemplates
directory
In this dir create two empty files:
start.cpp
ArduinoProject.cbp

Copy into start.cpp the lines below:

/*





 */

extern "C" void __cxa_pure_virtual(void); //for C++ defines

void __cxa_pure_virtual(void) {};
#include <WProgram.h>

void setup()
{

   Serial.begin(9600);
   Serial.println("Hello from Arduino Code::Blocks template");

}


void loop()
{


}

copy into ArduinoProject.cbp the lines below:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
      <FileVersion major="1" minor="6" />
      <Project>
            <Option title="ArduinoProject" />
            <Option pch_mode="2" />
            <Option compiler="avrgcc" />
            <Build>
                  <Target title="Debug">
                        <Option output="bin\Debug\ArduinoProject.elf" prefix_auto="1" extension_auto="0" />
                        <Option object_output="obj\Debug\" />
                        <Option type="1" />
                        <Option compiler="avrgcc" />
                  </Target>
                  <Target title="Release">
                        <Option output="bin\Release\ArduinoProject.elf" prefix_auto="1" extension_auto="0" />
                        <Option object_output="obj\Release\" />
                        <Option type="1" />
                        <Option compiler="avrgcc" />
                        <ExtraCommands>
                              <Add after="avr-size --mcu=atmega328p --format=avr $(TARGET_OUTPUT_FILE)" />
                              <Add after="avr-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex" />
                              <Add after="avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex" />
                              <Add after='cmd /c &quot;avr-objdump -h -S $(TARGET_OUTPUT_FILE) &gt; $(TARGET_OUTPUT_FILE).lss&quot;' />
                              <Add after="C:\_apps\arduino-0018\hardware\tools\avr\bin\avrdude.exe -CC:\_apps\arduino-0018\hardware\tools\avr\etc\avrdude.conf -v -v -v -v -pm328p -cstk500v1 -P\\.\COM4 -b 57600  -D -Uflash:w:${PROJECT_DIR}/${TARGET_OUTPUT_DIR}/${TARGET_OUTPUT_BASENAME}.elf.hex:a" />
                              <Mode after="always" />
                        </ExtraCommands>
                  </Target>
            </Build>
            <Compiler>
                  <Add option="-Os" />
                  <Add option="-Wall" />
                  <Add option="-mmcu=atmega328p" />
                  <Add option="-DF_CPU=16000000UL" />
            </Compiler>
            <Linker>
                  <Add option="-mmcu=atmega328p" />
                  <Add option="-Wl,-Map=$(TARGET_OUTPUT_FILE).map,--cref" />
                  <Add library="C:\_apps\arduino-0018\libArduinoCoreAT328p\core.a" />
            </Linker>
            <ExtraCommands>
                  <Add after="avr-size --mcu=atmega328p --format=avr $(TARGET_OUTPUT_FILE)" />
                  <Add after="avr-objcopy -O ihex -R .eeprom -R .eesafe $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).hex" />
                  <Add after="avr-objcopy --no-change-warnings -j .eeprom --change-section-lma .eeprom=0 -O ihex $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE).eep.hex" />
                  <Add after='cmd /c &quot;avr-objdump -h -S $(TARGET_OUTPUT_FILE) &gt; $(TARGET_OUTPUT_FILE).lss&quot;' />
            </ExtraCommands>
            <Unit filename="start.cpp">
                  <Option compilerVar="CC" />
            </Unit>
            <Extensions>
                  <code_completion />
                  <debugger />
            </Extensions>
      </Project>
</CodeBlocks_project_file>

Edit ArduinoProject.cbp file:
Replace C:_apps\arduino-0018\ with your Arduino install directory
Replace C:_apps\arduino-0018\libArduinoCoreAT328p\ with the directory where your Arduino IDE made the core.a file
Replace COM4 to the port of your arduino bord

Usage:
Run Code::Blocks
File menu->New->From template , choose User templates on the left and ArduinoProject on the right. When finished,
Build menu->Select target ->Release
Build menu->Build
After building, it starts to upload your program onto the arduino board.
Run Arduino IDE and click on Serial Monitor.
If you see in Serial Monitor the text:

Hello from Arduino Code::Blocks template

it works.

Please take into account, that I am new in Arduino, in C++ and Code::Blocks.

(I cannot put links into the post above because of the rules of this forum), So credits:

I got the infos from this tutorial:

http://www.johnhenryshammer.com/WOW2/pagesHowTo/atmelPage.php