User forums > Embedded development

CB and Arduino 1.6.x

<< < (2/13) > >>

AZ:

--- Quote from: stahta01 on June 18, 2016, 03:28:51 am ---I still NEED the FULL rebuild log!

A partial log is NOT enough for me to see possible issues.

And, where did the code you posted come from; it does NOT look like good C code to me.

Tim S.

--- End quote ---

it is NOT a good C/C++ code. It is a sketch file. As i'm learning here (https://www.arduino.cc/en/Hacking/BuildProcess).  Arduino converts the sketch file to proper c/cpp and only after that calls the g++ compiler.

Let me work on the _proper_ cpp file.


> I still NEED the FULL rebuild log!
I'm not sure where/what you need... I uploaded all information from the "build log" window.

AZ:
So i took step back and tried to compile the files by hand ( without CB).
Here is what i learned.
The ino file (in it's simplified form) is converted to a cpp with 3 lines:

--- Code: ---// save as Blink.cpp

#include "Arduino.h"
void setup();
void loop();
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

--- End code ---

that can be compiled with :

--- Code: ---avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10604 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR  -I. -I${CORE} Blink.cpp

--- End code ---

where CORE - /home/az/bin/arduino-1.6.5-r5/hardware/arduino/avr/cores/arduino

Next step up was to understand how Arduino (IDE) compiles the sketches (ino files).

 It seems that it copies *.cpp and *.c file to a temp directory adds a "Blink.cpp" and compiles them one by one then it links them all into one file before uploading to a board.

The arduino-1.6.5-r5/hardware/arduino/avr/cores/arduino/main.cpp is the actual "main" file, that calls all the functions from "Blink":

--- Code: ---#include <Arduino.h>

// Declared weak in Arduino.h to allow user redefinitions.
int atexit(void (* /*func*/ )()) { return 0; }

// Weak empty variant initialization function.
// May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() { }

int main(void)
{
init();

initVariant();

#if defined(USBCON)
USBDevice.attach();
#endif

setup();
   
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
       
return 0;
}


--- End code ---

Summary so far:
 a. arduino converts "ino" files to cpp by adding 3 lines to the top of the ino file.
 b. arduino copies all the c/cpp files into single temp location. One of these files is "main.cpp" that has calls to the functions in the Blink.cpp
 c. then arduino calls g++ to compile each of these files separately and links them into one file
 d. once completed, the file gets uploaded to the board.

So the cb project (probably) needs to make a copy of that main.cpp. and treat all "sketches" as libraries.
Next, since arduino copies all cpp/c files into one temp location and compiles and links them there, i would think, that either project wizard should do that or CB should use a build system.


P.S. cool. i just found the up-to-date ( and up to latest arduino version) build system - https://github.com/sudar/Arduino-Makefile

AZ:
I suspect Tim will yell at me again for not posting the complete log...
But here the entire log from "build log":

--- Code: ---
-------------- Clean: Arduino Uno in test_3 (compiler: GNU GCC Compiler for AVR)---------------

Cleaned "test_3 - Arduino Uno"

-------------- Build: Arduino Uno in test_3 (compiler: GNU GCC Compiler for AVR)---------------

avr-g++ -Wall -fno-exceptions -ffunction-sections -fdata-sections -x c++ -s -DF_CPU=16000000L -DARDUINO=103 -DUSE_EEPROM=0 -DUSE_ETHERNET=0 -DUSE_FIRMATA=0 -DUSE_LCD=0 -DUSE_LCD4884=0 -DUSE_OBD=0 -DUSE_SD=0 -DUSE_SERVO=0 -DUSE_SOFTSERIAL=0 -DUSE_SPI=0 -DUSE_STEPPER=0 -DUSE_TINYGPS=0 -DUSE_WIRE=0 -Os -mmcu=atmega328p -D__AVR_ATmega328P__ -I/home/az/bin/arduino-1.6.5-r5/hardware/arduino/avr/cores/arduino -I/home/az/bin/arduino-1.6.5-r5/libraries -I/home/az/bin/arduino-1.6.5-r5/hardware/arduino/avr/variants/standard -I/home/az/bin/arduino-1.6.5-r5/hardware/tools/ -c main.cpp -o .objs/main.o
avr-g++ -Wall -fno-exceptions -ffunction-sections -fdata-sections -x c++ -s -DF_CPU=16000000L -DARDUINO=103 -DUSE_EEPROM=0 -DUSE_ETHERNET=0 -DUSE_FIRMATA=0 -DUSE_LCD=0 -DUSE_LCD4884=0 -DUSE_OBD=0 -DUSE_SD=0 -DUSE_SERVO=0 -DUSE_SOFTSERIAL=0 -DUSE_SPI=0 -DUSE_STEPPER=0 -DUSE_TINYGPS=0 -DUSE_WIRE=0 -Os -mmcu=atmega328p -D__AVR_ATmega328P__ -I/home/az/bin/arduino-1.6.5-r5/hardware/arduino/avr/cores/arduino -I/home/az/bin/arduino-1.6.5-r5/libraries -I/home/az/bin/arduino-1.6.5-r5/hardware/arduino/avr/variants/standard -I/home/az/bin/arduino-1.6.5-r5/hardware/tools/ -c sketch.cpp -o .objs/sketch.o
avr-g++ -L/home/az/bin/arduino-1.6.5-r5/hardware/tools/avr -o bin/Release/test_3.elf .objs/main.o .objs/sketch.o  -Wl,--gc-sections -s -mmcu=atmega328p 
.objs/main.o: In function `main':
main.cpp:(.text.startup.main+0x0): undefined reference to `init'
.objs/sketch.o: In function `setup':
sketch.cpp:(.text.setup+0xa): undefined reference to `Serial'
sketch.cpp:(.text.setup+0xc): undefined reference to `Serial'
sketch.cpp:(.text.setup+0xe): undefined reference to `HardwareSerial::begin(unsigned long, unsigned char)'
sketch.cpp:(.text.setup+0x16): undefined reference to `pinMode'
.objs/sketch.o: In function `loop':
sketch.cpp:(.text.loop+0x4): undefined reference to `Serial'
sketch.cpp:(.text.loop+0x6): undefined reference to `Serial'
sketch.cpp:(.text.loop+0x8): undefined reference to `Print::println(char const*)'
sketch.cpp:(.text.loop+0x10): undefined reference to `digitalWrite'
sketch.cpp:(.text.loop+0x1c): undefined reference to `delay'
sketch.cpp:(.text.loop+0x24): undefined reference to `digitalWrite'
sketch.cpp:(.text.loop+0x30): undefined reference to `delay'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
13 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 

--- End code ---

I have 3 files in the project - main.cpp, sketch.cpp and pins_arduino.h .

yvesdm3000:
Your compiler is saying that it can't link some functions, normally this is because some libraries are not specified or missing.

Yves

oBFusCATed:
You need to build the files inside the Arduino that contain the code that is not defined.
In my wizard (probably in the original, too) this is done by adding files that are named the same as the on being compiled and their content is #include <Blabla.cpp>. Make sure you use <> instead of "".

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version