User forums > General (but related to Code::Blocks)

Undefined reference to main - first arduino project in code::blocks

(1/2) > >>

Windy:
Hi there,

I got sick of the arduino IDE, so I decided to switch to codeblocks. I installe codeblocks 13.12 and the arduino plugin form scottdky on my ubuntu 14.04 machine. I quiet liked the idea of different compiler settings for debugging and finaly building a release and upload it. If I use my "debugging" settings, the code compiles allright. Unfortunately it failes if I use my "compile and upload" settings.

To test the settings I try to compile the example below. I set the project up using scottdky's arduino project wizard, although I changed several settings and search directories...

--- Code: ---#include <Arduino.h>
/*
  Turns on an LED on for one second, then off for one second, repeatedly.
  This example code is in the public domain.
*/

void setup()
{
// initialize the digital pin as an output.
pinMode(5, OUTPUT);
}

void loop()
{
digitalWrite(5, HIGH);   // set the LED on
delay(1000);              // wait for a second
digitalWrite(5, LOW);    // set the LED off
delay(1000);              // wait for a second
}
--- End code ---

Here the output if i use the debugging settings:

--- Code: ----------------- Build: Simulator - Debug in Test (compiler: GNU GCC Compiler for AVR)---------------
Scanned 0 files for #includes, cache used 0, cache updated 0
avr-g++ -Wall -fno-exceptions -ffunction-sections -fdata-sections -x c++ -s -DARDUINO=101 -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 -g -DARDUSIM -DENABLE_API_NAME -D__AVR_ATmega2560__ -DF_CPU=16000000L -I../libraries/ArduinoHardware/arduino/avr/cores/arduino -I../libraries/ArduinoHardware/arduino/avr/variants/mega -I../libraries/ArduinoHardware/arduino/avr/libraries/Wire -c sketch.cpp -o obj/Debug/sketch.o
In file included from ../libraries/ArduinoHardware/arduino/avr/cores/arduino/USBAPI.h:27:0,
                 from ../libraries/ArduinoHardware/arduino/avr/cores/arduino/Arduino.h:226,
                 from sketch.cpp:1:
/usr/lib/avr/include/util/delay.h:95:3: warning: #warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed" [-Wcpp]
 # warning "Compiler optimizations disabled; functions from <util/delay.h> won't work as designed"
   ^
avr-g++  -o Test obj/Debug/sketch.o  -Wl,--gc-sections 
Output file is Test with size 17,37 KB
CWD for depslib was: /media/Data/Arduino_Workspace/Test.
CWD for depslib is: /media/Data/Arduino_Workspace/Test.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /media/STICK/Daten/Hubschrauber/Eigenbau/Arduino_Workspace/Test.
CWD for depslib is: /media/Data/Arduino_Workspace/Test.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /media/Data/Arduino_Workspace/Test.
CWD for depslib is: /media/Data/Arduino_Workspace/Test.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /media/Data/Eigenbau/Arduino_Workspace/Test.
CWD for depslib is: /media/Data/Arduino_Workspace/Test.
Scanned 0 files for #includes, cache used 0, cache updated 0
CWD for depslib was: /media/Data/Arduino_Workspace/Test.
CWD for depslib is: /media/Data/Arduino_Workspace/Test.
Scanned 0 files for #includes, cache used 0, cache updated 0
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 1 warning(s) (0 minute(s), 0 second(s))

--- End code ---

And here the output of my attempt using the "compile and upload" settings:

--- Code: ----------------- Build: Arduino Mega 2560/ADK in Test (compiler: GNU GCC Compiler for AVR)---------------
Scanned 0 files for #includes, cache used 0, cache updated 0
avr-g++ -Wall -fno-exceptions -ffunction-sections -fdata-sections -x c++ -s -DARDUINO=101 -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=atmega2560 -D__AVR_ATmega2560__ -DF_CPU=16000000L -DCODE_BLOCKS -I../libraries/ArduinoHardware/arduino/avr/cores/arduino -I../libraries/ArduinoHardware/arduino/avr/variants/mega -I../libraries/ArduinoHardware/arduino/avr/libraries/Wire -c sketch.cpp -o .objs/sketch.o
avr-g++  -o bin/Release/Test.elf .objs/sketch.o  -Wl,--gc-sections -s -mmcu=atmega2560 
/usr/lib/gcc/avr/4.8.2/../../../avr/lib/avr6/crtm2560.o: In Funktion `__bad_interrupt':
../../../../crt1/gcrt1.S:195: Undefined reference to `main'
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))

--- End code ---

Here the folder structure of /media/Data/Arduino_Workspace/. i got rid of most irrelevant folders...

--- Code: ---.
├── libraries
│   ├── ArduinoHardware
│   │   ├── arduino
│   │   │   └── avr
│   │   │       ├── boards.txt
│   │   │       ├── bootloaders
│   │   │       ├── cores
│   │   │       │   └── arduino
│   │   │       │       ├── abi.cpp
│   │   │       │       ├── Arduino.h
│   │   │       │       ├── binary.h
│   │   │       │       ├── CDC.cpp
│   │   │       │       ├── Client.h
│   │   │       │       ├── HardwareSerial0.cpp
│   │   │       │       ├── HardwareSerial1.cpp
│   │   │       │       ├── HardwareSerial2.cpp
│   │   │       │       ├── HardwareSerial3.cpp
│   │   │       │       ├── HardwareSerial.cpp
│   │   │       │       ├── HardwareSerial.h
│   │   │       │       ├── HardwareSerial_private.h
│   │   │       │       ├── HID.cpp
│   │   │       │       ├── hooks.c
│   │   │       │       ├── IPAddress.cpp
│   │   │       │       ├── IPAddress.h
│   │   │       │       ├── main.cpp
│   │   │       │       ├── new.cpp
│   │   │       │       ├── new.h
│   │   │       │       ├── Printable.h
│   │   │       │       ├── Print.cpp
│   │   │       │       ├── Print.h
│   │   │       │       ├── Server.h
│   │   │       │       ├── Stream.cpp
│   │   │       │       ├── Stream.h
│   │   │       │       ├── Tone.cpp
│   │   │       │       ├── Udp.h
│   │   │       │       ├── USBAPI.h
│   │   │       │       ├── USBCore.cpp
│   │   │       │       ├── USBCore.h
│   │   │       │       ├── USBDesc.h
│   │   │       │       ├── WCharacter.h
│   │   │       │       ├── WInterrupts.c
│   │   │       │       ├── wiring_analog.c
│   │   │       │       ├── wiring.c
│   │   │       │       ├── wiring_digital.c
│   │   │       │       ├── wiring_private.h
│   │   │       │       ├── wiring_pulse.c
│   │   │       │       ├── wiring_pulse.S
│   │   │       │       ├── wiring_shift.c
│   │   │       │       ├── WMath.cpp
│   │   │       │       ├── WString.cpp
│   │   │       │       └── WString.h
│   │   │       ├── firmwares
│   │   │       ├── libraries
│   │   │       │   ├── EEPROM
│   │   │       │   ├── SoftwareSerial
│   │   │       │   ├── SPI
│   │   │       │   └── Wire
│   │   │       ├── platform.txt
│   │   │       ├── programmers.txt
│   │   │       └── variants
│   │   │           ├── eightanaloginputs
│   │   │           ├── ethernet
│   │   │           ├── gemma
│   │   │           ├── leonardo
│   │   │           ├── mega
│   │   │           │   └── pins_arduino.h
│   │   │           ├── micro
│   │   │           ├── robot_control
│   │   │           ├── robot_motor
│   │   │           ├── standard
│   │   │           └── yun1
│   │   └── tools
└── Test
    ├── bin
    │   └── Release
    │       ├── Test.elf.eep.hex
    │       └── Test.elf.hex
    ├── cores
    │   ├── CDC.cpp
    │   ├── HardwareSerial.cpp
    │   ├── HID.cpp
    │   ├── IPAddress.cpp
    │   ├── main.cpp
    │   ├── new.cpp
    │   ├── Print.cpp
    │   ├── Stream.cpp
    │   ├── Tone.cpp
    │   ├── USBCore.cpp
    │   ├── WInterrupts.c
    │   ├── wiring_analog.c
    │   ├── wiring.c
    │   ├── wiring_digital.c
    │   ├── wiring_pulse.c
    │   ├── wiring_shift.c
    │   ├── WMath.cpp
    │   └── WString.cpp
    ├── libraries
    │   └── libraries.cpp
    ├── obj
    │   ├── Debug
    │   │   ├── cores
    │   │   │   ├── CDC.o
    │   │   │   ├── HardwareSerial.o
    │   │   │   ├── HID.o
    │   │   │   ├── IPAddress.o
    │   │   │   ├── main.o
    │   │   │   ├── new.o
    │   │   │   ├── Print.o
    │   │   │   ├── Stream.o
    │   │   │   ├── Tone.o
    │   │   │   ├── USBCore.o
    │   │   │   ├── WInterrupts.o
    │   │   │   ├── wiring_analog.o
    │   │   │   └── wiring.o
    │   │   ├── libraries
    │   │   │   └── ArduinoHardware
    │   │   │       └── arduino
    │   │   │           └── avr
    │   │   │               └── cores
    │   │   │                   └── arduino
    │   │   │                       └── main.o
    │   │   ├── sketch.o
    │   │   └── Test
    │   │       └── sketch.o
    │   └── Release
    │       ├── cores
    │       │   ├── CDC.o
    │       │   ├── HardwareSerial.o
    │       │   ├── HID.o
    │       │   ├── IPAddress.o
    │       │   ├── main.o
    │       │   ├── new.o
    │       │   ├── Print.o
    │       │   ├── Stream.o
    │       │   ├── Tone.o
    │       │   ├── USBCore.o
    │       │   ├── WInterrupts.o
    │       │   ├── wiring_analog.o
    │       │   └── wiring.o
    │       ├── libraries
    │       │   └── ArduinoHardware
    │       │       └── arduino
    │       │           └── avr
    │       │               └── cores
    │       │                   └── arduino
    │       │                       └── main.o
    │       ├── sketch.o
    │       └── Test
    │           └── sketch.o
    ├── sketch.cpp
    ├── Test
    ├── Test.cbp
    ├── Test.cbpbackup
    ├── Test.depend
    └── Test.layout

--- End code ---

I compared the compiler options and search for ages but can't find the cause of the error. The function main is defined in ./libraries/ArduinoHardware/arduino/avr/cores/arduino/main.cpp. I tried to include the file itselfe (which might not make sense at all...), I declared main in a main.h and included the headerfile to the search path but with no success. I tried to definde main in my sketch.cpp befor defining setup() and loop () which didn't help either. Any ideas? What am I missing?

Thanks in advance!
Windy

stahta01:
Later today I will try and see if I can duplicate the problem under Debian 8.1 "Jessie"

I have no arduino hardware; so, I hope that is NOT needed to dup the problem.
Likely be using CB Nightly on first dup attempt.
Failed: To even get as far as your error using  CB Nightly.

The error itself looks like a linking error to me.

Tim S.

Windy:
You don't need any arduino hardware...
Jap, that's a linking error. The "ld" after "error:" indicates that.

Windy

stahta01:
Could you attach the cbp file you are using for me to test that directly?
I believe you need to zip or 7zip it to attach it.

Tim S.


Windy:
cbp-File is attached.

Navigation

[0] Message Index

[#] Next page

Go to full version