6 Replies Latest reply on Jan 28, 2014 10:30 PM by Mikal.Hart

    Galileo Arduino compiler/linker error: Undefined Reference to Main

    Levller

      Hello, Getting the following compiler/linker error:

       

      C:/arduino-1.5.3/hardware/tools/x86/i586-poky-linux-uclibc/usr/lib/../lib/crt1.o: In function `_start':

      /dev/shm/kmsywula/tmp/work/i586-poky-linux-uclibc/uclibc/0.9.33+gitAUTOINC+946799cd0ce0c6c803c9cb173a84f4d607bde350-r8.4/git/libc/sysdeps/linux/i386/crt1.S:123: undefined reference to `main'

      collect2.exe: error: ld returned 1 exit status

       

      for the following code. Ideally, most of this code would be broken into .h and .cpp library files, but for the sake of the linker error, I've included them in the main.ino file. No effect, but might as well include everything, right?

       

      [quote]

      [color=#7E7E7E]//#include <kneeSensor.h> linker broken for Arduino for Intel Galileo IDE[/color]

      [color=#7E7E7E]//from <kneeSensor.h>[/color]

      using namespace std;

       

       

      [color=#7E7E7E]//define operating parameters[/color]

      #define S0_PIN 12

      #define S1_PIN 10

      #define MUXE_PIN 8

      #define MUX2_1 A0

      #define MUX2_2 A2

      #define MUX1_1 A4

      #define MUX1_2 A5

      #define BAUD_RATE 9600

       

       

      #define NGYROS 2

      #define NACCELS 2

       

      typedef [color=#CC6600]unsigned[/color] [color=#CC6600]char[/color] uchar;

       

      [color=#CC6600]class[/color] sensor{

      [color=#CC6600]private[/color][color=#7E7E7E][b]:[/b][/color]

        bool s0, s1;

        uchar pinx, piny;

        friend [color=#CC6600]class[/color] gyro;

        friend [color=#CC6600]class[/color] accel;

        [color=#CC6600]unsigned[/color] pollField(uchar pin); [color=#7E7E7E]//Mux Enable pin set low from controller constructor. Never needs to go high.[/color]

      };

       

       

      struct accelData{

        [color=#CC6600]unsigned[/color] x, y, z;

      };

       

       

      struct gyroData{

        [color=#CC6600]unsigned[/color] x, y;

      };

       

       

      [color=#CC6600]class[/color] accel: [color=#CC6600]private[/color] sensor{

      [color=#CC6600]private[/color][color=#7E7E7E][b]:[/b][/color]

        uchar pinz;

      [color=#CC6600]public[/color][color=#7E7E7E][b]:[/b][/color]

        accel(){};

        accel(uchar sel, uchar px, uchar py, uchar pz);

        [color=#CC6600]void[/color] accelinit(uchar sel, uchar px, uchar py, uchar pz);

        [color=#CC6600]void[/color] poll(accelData* res);

      };

       

       

      [color=#CC6600]class[/color] gyro: [color=#CC6600]private[/color] sensor{

      [color=#CC6600]public[/color][color=#7E7E7E][b]:[/b][/color]

        gyro(){};

        gyro(uchar sel, uchar px, uchar py);

        [color=#CC6600]void[/color] gyroinit(uchar sel0, uchar px, uchar py);

        [color=#CC6600]void[/color] poll(gyroData* res);

      };

       

       

      [color=#CC6600]class[/color] controller{

      [color=#CC6600]private[/color][color=#7E7E7E][b]:[/b][/color]

        accel accels[NACCELS];

        gyro gyros[NGYROS];

        accelData ad[NACCELS];

        gyroData gd[NGYROS];

      [color=#CC6600]public[/color][color=#7E7E7E][b]:[/b][/color]

        controller();

        [color=#CC6600]void[/color] fetchData();

        [color=#7E7E7E]//filter(); filtering not used at this time. Low pass filter implemented in future?[/color]

        [color=#CC6600]void[/color] sendData();

      };

       

       

      [color=#7E7E7E]//using namespace std;[/color]

       

       

      [color=#7E7E7E]//arduino uses an initialization Setup() function and a main loop() function[/color]

      [color=#7E7E7E]//Because of the multiple function compilation, controller object must be accessible globally.[/color]

      [color=#7E7E7E]//hence:[/color]

      controller* control;

       

       

      [color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color](){

        control = [color=#CC6600]new[/color] controller();

      }

       

       

      [color=#CC6600]void[/color] [color=#CC6600][b]loop[/b][/color](){

        control->fetchData();

        control->sendData();

      }

       

       

      [color=#7E7E7E]//from kneeSensor.cpp[/color]

      [color=#7E7E7E][b]gyro:[/b][/color]:gyro(uchar sel, uchar px, uchar py){

        s0 = (sel & 1) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color]; [color=#7E7E7E]//if sel1 & 1 is true, s0 is true otherwise false;[/color]

        s1 = (sel & 2) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color];[color=#7E7E7E]//etc.[/color]

       

        pinx = px;

        piny = py;

      }

       

       

      [color=#CC6600]void[/color] gyro::gyroinit(uchar sel, uchar px, uchar py){

        s0 = (sel & 1) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color]; [color=#7E7E7E]//if sel1 & 1 is true, s0 is true otherwise false;[/color]

        s1 = (sel & 2) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color];[color=#7E7E7E]//etc.[/color]

       

        pinx = px;

        piny = py;

      }

      [color=#7E7E7E][b]accel:[/b][/color]:accel(uchar sel, uchar px, uchar py, uchar pz){

        s0 = (sel & 1) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color]; [color=#7E7E7E]//if sel1 & 1 is true, s0 is true otherwise false;[/color]

        s1 = (sel & 2) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color];[color=#7E7E7E]//etc.[/color]

       

        pinx = px;

        piny = py;

        pinz = pz;

      }

       

       

      [color=#CC6600]void[/color] accel::accelinit(uchar sel, uchar px, uchar py, uchar pz){

        s0 = (sel & 1) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color]; [color=#7E7E7E]//if sel1 & 1 is true, s0 is true otherwise false;[/color]

        s1 = (sel & 2) ? [color=#CC6600]true[/color] : [color=#CC6600]false[/color];[color=#7E7E7E]//etc.[/color]

       

        pinx = px;

        piny = py;

        pinz = pz;

      }

       

       

      [color=#CC6600]void[/color] accel::poll(accelData* res){

        [color=#CC6600]digitalWrite[/color](S0_PIN, s0);

        [color=#CC6600]digitalWrite[/color](S1_PIN, s1);

       

        res->x = pollField(pinx);

        res->y = pollField(piny);

        res->z = pollField(pinz);

      }

       

       

      [color=#CC6600]unsigned[/color] sensor::pollField(uchar pin){

        [color=#CC6600]return[/color] [color=#CC6600]analogRead[/color](pin);

      }

       

       

      [color=#CC6600]void[/color] gyro::poll(gyroData* res){

        [color=#CC6600]digitalWrite[/color](S0_PIN, s0);

        [color=#CC6600]digitalWrite[/color](S1_PIN, s1);

       

        res->x = pollField(pinx);

        res->y = pollField(piny);

      }

       

       

      [color=#7E7E7E][b]controller:[/b][/color]:controller(){

        [color=#7E7E7E]//set mux controls as output[/color]

        [color=#CC6600]pinMode[/color](S0_PIN, [color=#006699]OUTPUT[/color]);

        [color=#CC6600]pinMode[/color](S1_PIN, [color=#006699]OUTPUT[/color]);

       

        [color=#7E7E7E]//enable muxes[/color]

        [color=#CC6600]pinMode[/color](MUXE_PIN, [color=#006699]OUTPUT[/color]);

        [color=#CC6600]digitalWrite[/color](MUXE_PIN, [color=#006699]LOW[/color]);

       

        [color=#7E7E7E]//initialize virtual interface for sensors[/color]

        accels[0].accelinit(0, MUX1_1, MUX1_2, MUX2_1);

        accels[1].accelinit(1, MUX1_1, MUX1_2, MUX2_2);

        gyros[0].gyroinit(3, MUX1_1, MUX1_2);

        gyros[1].gyroinit(3, MUX2_1, MUX2_2);

       

        [color=#7E7E7E]//intialize USB CDC serial connection[/color]

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](BAUD_RATE);

      }

       

       

      [color=#CC6600]void[/color] controller::fetchData(){

        [color=#CC6600]for[/color]([color=#CC6600]unsigned[/color] i = 0; i < NACCELS; i++){

        accels[i].poll(&ad[i]);

        }

       

        [color=#CC6600]for[/color]([color=#CC6600]unsigned[/color] i = 0; i < NGYROS; i++){

        gyros[i].poll(&gd[i]);

        }

      }

       

       

      [color=#CC6600]void[/color] controller::sendData(){

        [color=#CC6600]for[/color]([color=#CC6600]unsigned[/color] i = 0; i < NACCELS; i++){

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](ad[i].x);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]","[/color]);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](ad[i].y);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]","[/color]);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](ad[i].z);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]","[/color]);

        }

       

        [color=#CC6600]for[/color]([color=#CC6600]unsigned[/color] i = 0; i < NGYROS; i++){

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](gd[i].x);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]","[/color]);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color](gd[i].y);

        [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]print[/color]([color=#006699]","[/color]);

        }

      }

       

      The path associated with the error (included above) looks like it's trying to compile something from the Poky Linux distribution, which is completely unrelated. I'd love any assistance or thoughts anyone has on this.quar

       

       

       

      [/quote]

        • 1. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
          Levller

          That code formatting didn't work. Try this.

           

          //#include <kneeSensor.h> linker broken for Arduino for Intel Galileo IDE

          //from <kneeSensor.h>

          using namespace std;

           

           

          //define operating parameters

          #define S0_PIN 12

          #define S1_PIN 10

          #define MUXE_PIN 8

          #define MUX2_1 A0

          #define MUX2_2 A2

          #define MUX1_1 A4

          #define MUX1_2 A5

          #define BAUD_RATE 9600

           

           

          #define NGYROS 2

          #define NACCELS 2

           

          typedef unsigned char uchar;

           

          class sensor{

          private:

            bool s0, s1;

            uchar pinx, piny;

            friend class gyro;

            friend class accel;

            unsigned pollField(uchar pin); //Mux Enable pin set low from controller constructor. Never needs to go high.

          };

           

           

          struct accelData{

            unsigned x, y, z;

          };

           

           

          struct gyroData{

            unsigned x, y;

          };

           

           

          class accel: private sensor{

          private:

            uchar pinz;

          public:

            accel(){};

            accel(uchar sel, uchar px, uchar py, uchar pz);

            void accelinit(uchar sel, uchar px, uchar py, uchar pz);

            void poll(accelData* res);

          };

           

           

          class gyro: private sensor{

          public:

            gyro(){};

            gyro(uchar sel, uchar px, uchar py);

            void gyroinit(uchar sel0, uchar px, uchar py);

            void poll(gyroData* res);

          };

           

           

          class controller{

          private:

            accel accels[NACCELS];

            gyro gyros[NGYROS];

            accelData ad[NACCELS];

            gyroData gd[NGYROS];

          public:

            controller();

            void fetchData();

            //filter(); filtering not used at this time. Low pass filter implemented in future?

            void sendData();

          };

           

           

          //using namespace std;

           

           

          //arduino uses an initialization Setup() function and a main loop() function

          //Because of the multiple function compilation, controller object must be accessible globally.

          //hence:

          controller* control;

           

           

          void setup(){

            control = new controller();

          }

           

           

          void loop(){

            control->fetchData();

            control->sendData();

          }

           

           

          //from kneeSensor.cpp

          gyro::gyro(uchar sel, uchar px, uchar py){

            s0 = (sel & 1) ? true : false; //if sel1 & 1 is true, s0 is true otherwise false;

            s1 = (sel & 2) ? true : false;//etc.

           

            pinx = px;

            piny = py;

          }

           

           

          void gyro::gyroinit(uchar sel, uchar px, uchar py){

            s0 = (sel & 1) ? true : false; //if sel1 & 1 is true, s0 is true otherwise false;

            s1 = (sel & 2) ? true : false;//etc.

           

            pinx = px;

            piny = py;

          }

          accel::accel(uchar sel, uchar px, uchar py, uchar pz){

            s0 = (sel & 1) ? true : false; //if sel1 & 1 is true, s0 is true otherwise false;

            s1 = (sel & 2) ? true : false;//etc.

           

            pinx = px;

            piny = py;

            pinz = pz;

          }

           

           

          void accel::accelinit(uchar sel, uchar px, uchar py, uchar pz){

            s0 = (sel & 1) ? true : false; //if sel1 & 1 is true, s0 is true otherwise false;

            s1 = (sel & 2) ? true : false;//etc.

           

            pinx = px;

            piny = py;

            pinz = pz;

          }

           

           

          void accel::poll(accelData* res){

            digitalWrite(S0_PIN, s0);

            digitalWrite(S1_PIN, s1);

           

            res->x = pollField(pinx);

            res->y = pollField(piny);

            res->z = pollField(pinz);

          }

           

           

          unsigned sensor::pollField(uchar pin){

            return analogRead(pin);

          }

           

           

          void gyro::poll(gyroData* res){

            digitalWrite(S0_PIN, s0);

            digitalWrite(S1_PIN, s1);

           

            res->x = pollField(pinx);

            res->y = pollField(piny);

          }

           

           

          controller::controller(){

            //set mux controls as output

            pinMode(S0_PIN, OUTPUT);

            pinMode(S1_PIN, OUTPUT);

           

            //enable muxes

            pinMode(MUXE_PIN, OUTPUT);

            digitalWrite(MUXE_PIN, LOW);

           

            //initialize virtual interface for sensors

            accels[0].accelinit(0, MUX1_1, MUX1_2, MUX2_1);

            accels[1].accelinit(1, MUX1_1, MUX1_2, MUX2_2);

            gyros[0].gyroinit(3, MUX1_1, MUX1_2);

            gyros[1].gyroinit(3, MUX2_1, MUX2_2);

           

            //intialize USB CDC serial connection

            Serial.begin(BAUD_RATE);

          }

           

           

          void controller::fetchData(){

            for(unsigned i = 0; i < NACCELS; i++){

            accels[i].poll(&ad[i]);

            }

           

            for(unsigned i = 0; i < NGYROS; i++){

            gyros[i].poll(&gd[i]);

            }

          }

           

           

          void controller::sendData(){

            for(unsigned i = 0; i < NACCELS; i++){

            Serial.print(ad[i].x);

            Serial.print(",");

            Serial.print(ad[i].y);

            Serial.print(",");

            Serial.print(ad[i].z);

            Serial.print(",");

            }

           

            for(unsigned i = 0; i < NGYROS; i++){

            Serial.print(gd[i].x);

            Serial.print(",");

            Serial.print(gd[i].y);

            Serial.print(",");

            }

          }

          • 2. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
            Mikal.Hart

            Hmm.. That same sketch compiles fine in my (Galileo) Arduino IDE.  I assume you're compiling it in the IDE, right?  If so, you might enable verbose compilation errors (File/Preferences).

            • 3. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
              rmm200

              Just to add a second data point - it compiles clean within the IDE for me too.

              • 4. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
                Mikal.Hart

                rmm200-- If that's your "second data point", I have to infer that you initially tried to compile the program for the Galileo outside the IDE--something you didn't mention.  In that case I understand the problem.

                 

                A normal C/C++ program has a main() entry point that the programmer is expected to provide.  In Arduino-land it's a little different.  Here we write setup() and loop() routines which are called by a hidden main() program that the development environment provides behind the scenes.  Something like:

                 

                void main()

                {

                  setup();

                  while (true)

                    loop();

                }

                 

                Since you are compiling in an environment that expects a main() you might add that one.

                 

                Mikal

                • 5. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
                  rmm200

                  Don't reply to me - I was just seconding that it compiles clean within the IDE. I tried nothing else.

                  • 6. Re: Galileo Arduino compiler/linker error: Undefined Reference to Main
                    Mikal.Hart

                    Ah, whoops!  I'm a little confused, apparently.  I see that you are NOT the OP.  Sorry!

                     

                    Nevertheless, my guess is that either Levller is trying to compile an Arduino sketch outside the Arduino IDE, or else his IDE is damaged somehow.