Some progresses on this but a new problem appeared.
I worked with the theory that we should use -lm instead of -lgcc for floating points operations during the linking process of the elf file. The same problem can be found in the internet: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=printview&t=56149&start=0
I've executed manually the final CMake linking step which fails and with can be found in "CMakeFiles/arduino_sample_name.dir/link.txt". This is what it contains:
avr-g++ -O3 -lm -ffunction-sections -fdata-sections -fno-tree-loop-optimize -fno-move-loop-invariants -mmcu=atmega328p CMakeFiles/hello_world_arduino.dir/src/hello_world.cpp.o CMakeFiles/hello_world_arduino.dir/src/ros_lib/time.cpp.o CMakeFiles/hello_world_arduino.dir/src/ros_lib/duration.cpp.o CMakeFiles/hello_world_arduino.dir/opt/ros/electric/stacks/rosserial/rosserial_arduino/cmake_scripts/cc_support.cpp.o -o hello_world_arduino.elf -Wl,--as-needed -Wl,--relax -Wl,--gc-sections libatmega328_CORE.a -lm
Here we can see the -lm as the last parameter. I added it through the CMakeList.txt command. However this does not solve the problem:
set(${FIRMWARE_NAME}_LIBS m)
The arduino software includes a makefile "Arduino.mk" which allows to compile through the command line and with which it is possible to compile the TimeTF example. This "Arduino.mk" has an subtle difference with the ""CMakeFiles/arduino_sample_name.dir/link.txt" in the linking command: the -lm argument was included as one of the firsts arguments.
Trying to mimic this behaviour I modified the rosserial_arduino/cmake_scripts/toolchains/Arduino.cmake. First I tried to modify the ARDUINO_LINKER_FLAGS without success. Finally it was possible modifiyng the CPP_FLAGS variable.
--- rosserial_arduino/cmake_scripts/toolchains/Arduino.cmake 2011-12-01 00:49:27.000000000 +0100
+++ rosserial_arduino/cmake_scripts/toolchains/Arduino.cmake2 2011-12-01 00:49:20.000000000 +0100
@@ -76,7 +76,7 @@
# C only fine tunning
set(TUNNING_FLAGS "-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums")
-SET(CPP_FLAGS "-lm -ffunction-sections -fdata-sections -fno-tree-loop-optimize -fno-move-loop-invariants")
+SET(CPP_FLAGS " -ffunction-sections -fdata-sections -fno-tree-loop-optimize -fno-move-loop-invariants")
set(CMAKE_CXX_FLAGS " -O3 ${CPP_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} ${TUNNING_FLAGS} -Wall -Wstrict-prototypes -std=gnu99 ${CPP_FLAGS}")
Then my "hello_world_arduino" example inspired on "TimeTF" example compiled.
Linking CXX static library libatmega328_CORE.a
[ 76%] Built target atmega328_CORE
Scanning dependencies of target hello_world_arduino
[ 82%] Building CXX object CMakeFiles/hello_world_arduino.dir/src/hello_world.cpp.o
[ 88%] Building CXX object CMakeFiles/hello_world_arduino.dir/src/ros_lib/time.cpp.o
[ 94%] Building CXX object CMakeFiles/hello_world_arduino.dir/src/ros_lib/duration.cpp.o
[100%] Building CXX object CMakeFiles/hello_world_arduino.dir/opt/ros/electric/stacks/rosserial/rosserial_arduino/cmake_scripts/cc_support.cpp.o
Linking CXX executable hello_world_arduino.elf
[100%] Built target hello_world_arduino
Everything seemed perfect to me but in the end I got some integrity errors during the upload process:
[ 76%] Built target atmega328_CORE
[100%] Built target hello_world_arduino
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "hello_world_arduino.hex"
avrdude: writing flash (31224 bytes):
Writing | ################################################## | 100% 8.49s
avrdude: 31224 bytes of flash written
avrdude: verifying flash memory against hello_world_arduino.hex:
avrdude: load ...
(more)