Author Topic: Can't build code that works on Arduino IDE  (Read 6928 times)

Offline d00m

  • Single posting newcomer
  • *
  • Posts: 7
Can't build code that works on Arduino IDE
« on: October 20, 2015, 11:59:18 pm »
Hello, I have some issues with latest CodeBlocks for Arduino.

It doesn't build code that has been built successfully in Arduino IDE.
Let me explain a bit my problem.
I have Anarduino MiniWireless and couple thermo sensors DS18B20 connected to it.
I'm using code from this web page:
http://www.hobbytronics.co.uk/ds18b20-arduino

Code: [Select]
#include <OneWire.h>
#include <DallasTemperature.h>
 
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
 
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
 
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
 
void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");

  // Start up the library
  sensors.begin();
}
 
 
void loop(void)
{
  // call sensors.requestTemperatures() to issue a global temperature
  // request to all devices on the bus
  Serial.print(" Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");

  Serial.print("Temperature for Device 1 is: ");
  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
    // You can have more than one IC on the same bus.
    // 0 refers to the first IC on the wire
 
}


I've copied OneWire and DallasTemperature Modules into library directory and added path to them in Build settings for project.

and after Build I receive such errors:

Code: [Select]
arduino\libraries\OneWire\OneWire.cpp|470|warning: only initialized variables can be placed into program memory area|
||=== Build: Arduino Duemilanove (328) in sensors (compiler: GNU AVR GCC Compiler) ===|
build\sensors.o||In function `global constructors keyed to oneWire':|
sensors.ino:(.text._GLOBAL__I_oneWire+0x16)||undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'|
build\sensors.o||In function `loop':|
sensors.ino:(.text.loop+0x20)||undefined reference to `DallasTemperature::requestTemperatures()'|
sensors.ino:(.text.loop+0x3c)||undefined reference to `DallasTemperature::getTempCByIndex(unsigned char)'|
build\sensors.o||In function `setup':|
sensors.ino:(.text.setup+0x24)||undefined reference to `DallasTemperature::begin()'|
||=== Build failed: 4 error(s), 1 warning(s) (0 minute(s), 2 second(s)) ===|


What does it mean this error ?

"In function `global constructors keyed to oneWire': undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'"

Seems something wrong with passing references in CodeBlocks.
Please advice.
« Last Edit: October 21, 2015, 12:01:21 am by d00m »

Offline pirx67

  • Multiple posting newcomer
  • *
  • Posts: 35
Re: Can't build code that works on Arduino IDE
« Reply #1 on: October 21, 2015, 12:37:29 am »
At first a warning: I don't know the Code::Blocks for Arduino environment. And I used the Arduino IDE only a short time some years ago.

A basic hint: For reporting a compiler problem please use the directions mentioned at http://wiki.codeblocks.org/index.php/FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F.

Unfortunately you only added the output of the "Build messages" tab only and not the content of the "Build log" which is much more verbose.

The problem with the "undefined reference" comes up in the linking stage because the linker doesn't know where to find the compiled objects
of the classes you promised to have by including <OneWire.h> and <DallasTemperature.h>.

I don't know if it suffices to copy their sources in the library directory. Also you didn't mention what path you adapted in the build settings
of the project. As far as I remember the Arduino IDE would then build new sources in the library directory automatically.

I don't know if the Code::Blocks for Arduino environment should also do this automatically. Did Code::Blocks ever compile the library sources
into object files or a static library? In any case you must find the compiled objects anywhere in the tree if the linking stage for your project
shall have a chance to be successful.

This may not be so much useful but may give you some input to think about.

pirx

Online stahta01

  • Lives here!
  • ****
  • Posts: 6794
    • My Best Post
Re: Can't build code that works on Arduino IDE
« Reply #2 on: October 21, 2015, 03:29:33 am »
1. If you are using the Code::Blocks IDE Please state the version of it. And, the version info on the Compiler you are using.

2. If using "CodeBlocks Arduino IDE" please read and report the problem on its website http://arduinodev.com/codeblocks/

Tim S.
« Last Edit: October 21, 2015, 01:20:29 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline d00m

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't build code that works on Arduino IDE
« Reply #3 on: October 21, 2015, 10:52:35 am »
Hello,

Thank for your answers.
There is full build log:

Code: [Select]
Running target pre-build steps
D:\snowrail\CodeBlocks-Arduino-20140626\CodeBlocks\ArduinoUploader "D:\snowrail\sensors\." duemilanove328 - 16 0 "D:\snowrail\sensors\build\/lib_duemilanove328_16.a" "D:\snowrail\sensors\build\/core_duemilanove328_16.a"
Arduino Compiler & Uploader Version 0.8.9
(C)2013 Developed by Stanley Huang <[email protected]>, distributed under GPL license
arduino/libraries/OneWire/OneWire.cpp:470: warning: only initialized variables can be placed into program memory area
Build Target: Arduino Duemilanove (328) (MCU: atmega328p)
Referenced libraries: [OneWire]
Compiling library [OneWire]...
avr-g++ -c -Os -s -pipe -fno-exceptions -ffunction-sections -fdata-sections -MMD -DARDUINO=105 -DF_CPU=16000000L -mmcu=atmega328p -Iarduino/hardware/arduino/cores/arduino -Iarduino/hardware/arduino/variants/standard -Iarduino/libraries/OneWire "arduino/libraries/OneWire/OneWire.cpp" -o "C:\Users\ramz\AppData\Local\Temp/OneWire.cpp.o"

-------------- Build: Arduino Duemilanove (328) in sensors (compiler: GNU AVR GCC Compiler)---------------

Linking console executable: build\sensors_duemilanove328.elf
build\sensors.o: In function `global constructors keyed to oneWire':
sensors.ino:(.text._GLOBAL__I_oneWire+0x16): undefined reference to `DallasTemperature::DallasTemperature(OneWire*)'
build\sensors.o: In function `loop':
sensors.ino:(.text.loop+0x20): undefined reference to `DallasTemperature::requestTemperatures()'
sensors.ino:(.text.loop+0x3c): undefined reference to `DallasTemperature::getTempCByIndex(unsigned char)'
build\sensors.o: In function `setup':
sensors.ino:(.text.setup+0x24): undefined reference to `DallasTemperature::begin()'
Process terminated with status 1 (0 minute(s), 2 second(s))
4 error(s), 1 warning(s) (0 minute(s), 2 second(s))
 


copied folders with libraries from Arduino IDE into folder with libraries for CodeBlocks:
d:\snowrail\CodeBlocks-Arduino-20140626\CodeBlocks\arduino\libraries\

so I have:
d:\snowrail\CodeBlocks-Arduino-20140626\CodeBlocks\arduino\libraries\dallas-temperature-control\
d:\snowrail\CodeBlocks-Arduino-20140626\CodeBlocks\arduino\libraries\OneWire\

Then I modify Build options for project -> Arduino Duemilanove(328) -> Search directories tab -> Compiler tab -> Add two options: $(ARDUINO_DIR)\libraries\OneWire and $(ARDUINO_DIR)\libraries\dallas-temperature-control

Without this modification it did'n work at all - did't fount library 
#include <OneWire.h>
#include <DallasTemperature.h>

and of course I've added #include <Arduino.h>

I'm using  Code::Blocks 13.12 rev 9501
SDK Version 1.19.0

I've downloaded it from http://sourceforge.net/projects/arduinodev/files/
CodeBlocks-Arduino-20140626.7z
So I need go to http://arduinodev.com/forums/ ?
« Last Edit: October 21, 2015, 11:26:58 am by d00m »

Online stahta01

  • Lives here!
  • ****
  • Posts: 6794
    • My Best Post
Re: Can't build code that works on Arduino IDE
« Reply #4 on: October 21, 2015, 01:25:49 pm »
So I need go to http://arduinodev.com/forums/ ?

If you want fast answer then, yes.
Your post is really NOT on topic on this site; so, it will NOT likely get answered fast or might even get locked as being off topic too far.
Your problem is a Arduino Compiler, Library, or user coding issue; not a Code::Blocks issue.

A better site than http://arduinodev.com/forums might be an Arduino support site that nows about the Arduino Compiler and the Libraries you are using. I have no idea if or where that site would be.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline d00m

  • Single posting newcomer
  • *
  • Posts: 7
Re: Can't build code that works on Arduino IDE
« Reply #5 on: October 21, 2015, 01:30:45 pm »
Hello,

I've just fixed this issue.

I had to add .cpp and .h library files into my project folder AND - add these files into project in CodeBlocks.
After that everything goes ok.

Thank for your point to http://arduinodev.com/forums/
I've fouln such hint there:
http://freematics.com/forum/viewtopic.php?f=6&t=1573